Get current Matrix cell

MaximeDawns
Member Posts: 10
Hi,
I'll try to be clear on that one. I want to get the column ID i'm currently focusing. For example, in the screenshot :
1. The user type default values in Area 1 (Red)
2. He focuses the cell he wants the default values to be typed (Area 2 in blue + Area 5 in pink)
3. When he presses enter on the cell, the line is created in Area 3 (green) with the correct "Resource No." and "Date"
Problem is, if I just type the data manually, it'll work because in the code I passed 1, 2, 3 etc... depending on which "OnAfterValidate" it is. And i want to use the button marked as 4 ("Create Line") to automatically fill the value "10" (in area 1) into the cell i'm focusing.
Is there any way to achieve it ? The only thing to have is basically the currently focused column ID (from 1 to 12 in this example).

Thanks.
I'll try to be clear on that one. I want to get the column ID i'm currently focusing. For example, in the screenshot :
1. The user type default values in Area 1 (Red)
2. He focuses the cell he wants the default values to be typed (Area 2 in blue + Area 5 in pink)
3. When he presses enter on the cell, the line is created in Area 3 (green) with the correct "Resource No." and "Date"
Problem is, if I just type the data manually, it'll work because in the code I passed 1, 2, 3 etc... depending on which "OnAfterValidate" it is. And i want to use the button marked as 4 ("Create Line") to automatically fill the value "10" (in area 1) into the cell i'm focusing.
Is there any way to achieve it ? The only thing to have is basically the currently focused column ID (from 1 to 12 in this example).

Thanks.
0
Best Answer
-
You can use Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid.DataGrid.CurrentCell.ColumnIndex to get you need.
Hard task is to get BusinessGrid dot net variable for your page. I make it so:
1. Add to you page ControlAddin Microsoft.Dynamics.Nav.Client.PageReady
2. In trigger PageReady::AddInReady() write this code:
//PageID - number of your page, ControlID - number of repeater
//Global Variable
//FormCollection System.Windows.Forms.FormCollection.'System.Windows.Forms
//String System.String
//CurrForm System.Windows.Forms.Form
//ArrayControls System.Array
//BusinessGrid Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid
//Application System.Windows.Forms.Application
FormID := String.Format('{0:X8}',PageID);
RepeaterID := String.Format('{0:X4}',ControlID);
FormCollection := Application.OpenForms;
CurrForm := FormCollection.Item(FormCollection.Count-1);
RepeaterID := COPYSTR(CurrForm.Name,1,15) + RepeaterID + '-0008-' + COPYSTR(CurrForm.Name,26);
ArrayControls := CurrForm.Controls.Find(RepeaterID, TRUE);
IF ArrayControls.Length = 0 THEN EXIT;
BusinessGrid := ArrayControls.GetValue(0);
3. In you action button
MESSAGE('%1',BusinessGrid.DataGrid.CurrentCell.ColumnIndex);
It Is only column index in grid, get some method and properties to get additional info about column.
PS
It seems that this method not work when page opens in work area.
5
Answers
-
You can use Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid.DataGrid.CurrentCell.ColumnIndex to get you need.
Hard task is to get BusinessGrid dot net variable for your page. I make it so:
1. Add to you page ControlAddin Microsoft.Dynamics.Nav.Client.PageReady
2. In trigger PageReady::AddInReady() write this code:
//PageID - number of your page, ControlID - number of repeater
//Global Variable
//FormCollection System.Windows.Forms.FormCollection.'System.Windows.Forms
//String System.String
//CurrForm System.Windows.Forms.Form
//ArrayControls System.Array
//BusinessGrid Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid
//Application System.Windows.Forms.Application
FormID := String.Format('{0:X8}',PageID);
RepeaterID := String.Format('{0:X4}',ControlID);
FormCollection := Application.OpenForms;
CurrForm := FormCollection.Item(FormCollection.Count-1);
RepeaterID := COPYSTR(CurrForm.Name,1,15) + RepeaterID + '-0008-' + COPYSTR(CurrForm.Name,26);
ArrayControls := CurrForm.Controls.Find(RepeaterID, TRUE);
IF ArrayControls.Length = 0 THEN EXIT;
BusinessGrid := ArrayControls.GetValue(0);
3. In you action button
MESSAGE('%1',BusinessGrid.DataGrid.CurrentCell.ColumnIndex);
It Is only column index in grid, get some method and properties to get additional info about column.
PS
It seems that this method not work when page opens in work area.
5 -
OK i'll give it a try. But I can't actually find this assembly : Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid
I only get this for "Microsoft.Dynamics.Framework"
In the "Server" Tab
0 -
Copy needed component from \\RoleTailored Client\ to \\RoleTailored Client\Add-ins\0
-
Alright ! All variables set now (thanks a lot for your help by the way). Now two error messages.
First when I open the page :
Second, when I click the Action :
I think the error might wome from what you call "PageID" and "RepeaterID". Here's what i took :
Page ID :
And RepeaterID :
0 -
[Topic moved from 'NAV Tips & Tricks' forum to 'NAV Three Tier' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!1 -
PageID It is Object ID
RepeaterID is ok but better make for example number = 1, it is not ok for big value (i do not know why)
And i forgot to say that dot net variables must be declared RunOnClient=Yes.1 -
Ok so now, page is opening then closing instantly, wiht no error message0
-
Tried commenting and uncommenting line by line. Appears to be this line causing the issue of instant closing:
lFormCollection := lApplication.OpenForms;
0 -
CurrForm and BusinessGrid variables should be global.1
-
Alright ! I don't really get why CurrForm has to be Global but ok. It's working properly now. Thanks guys0
-
If variable is local it is destroyed after using. If variable is global it is alive until page opened.
In dot net, variables transfers by reference, so your Currform variable it is single reference to page. And when variable cleared it is destroy own page.1 -
Hi
Where do you find the dll:
Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid.DataGrid.CurrentCell.ColumnIndex
I only have these ?
0 -
One level up0
-
It aint here either...
0 -
Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid(dot net variable) part of
Microsoft.Dynamics.Framework.UI.WinForms.Controls.dll0 -
Still no luck - I can not get deeper into the: Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid...
Do you make this in AL or C/AL
When I registrate the
Microsoft.Dynamics.Framework.UI.WinForms.Controls.BusinessGrid in my Variables I do not get any triggers in the page??0 -
Sorry - Forgot to enable triggers0
-
sorry to ask again - but I can not find these 2 in the DotNet system...
//String System.String
//ArrayControls System.Array0 -
Google can help you bro0
-
Hi
It is mostly working now - but I get this message - it seems like the pageReady code dont are executed - when should that be run?
0 -
Hi all, I have the error
clicking on action.
The code in the AddinReady trigger do not start. I add the add-in in the property of cell of matrix. Is that correct?
Can you help me?
Thanks
Edit:
Resolved adding new field without source so that the event is now triggered.
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions