We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Find operation in grouping grid control

Hello, I am looking for a way to get the row index given the cell value and column index in the grouping grid control (without having to loop through the entire column). I found a sample in one of the forums but it doesn''t work for the grouping grid. Any help is appreciated. Thanks Shipra

21 Replies

AD Administrator Syncfusion Team March 19, 2005 07:35 PM UTC

Hi Shipra, the grouping grid offers two options to locate a record in a table. If you have the record index in your underlying datasource, you can call Record r = grid.Table.UnsortedRecords[recordIndex]; int rowIndexinGrid = grid.Table.DisplayElements.IndexOf(r); to first get the the record and then the row index in the grid. If you have a primary key for the record you are looking for, you can call Record r = grid.Table.Records.FindRecord(primaryKey); int rowIndexinGrid = grid.Table.DisplayElements.IndexOf(r); If you do want to implement a find method that lets you search any column and you do not want to loop through the records, you could use Query/Filter operations provided by the dataset or the underlying database. If you have a SQL Database or mdb file as datasource you could create a SQL query that returns the records that match your search criteria together with the primary key for each record. If you only have a DataSet you could create a copy the dataset then apply a RowFilter to filter the records in the dataset. Using the primary keys from the filtered records you could then locate the records in the GroupingGrid. Stefan >Hello, > >I am looking for a way to get the row index given the cell value and column index in the grouping grid control (without having to loop through the entire column). I found a sample in one of the forums but it doesn''t work for the grouping grid. Any help is appreciated. > >Thanks >Shipra > >


SG Shipra Gupta March 21, 2005 06:00 PM UTC

Hello Stefan, Thanks for your reply. In my application, I don''t have the record index from the underlying datasource, so the first option won''t work for me. But I do have the primary key for the record, so the second choice seems reasonable. But the problem is that the code sample you sent, didn''t work. I am using version 2.1.0.50 and there is no FindRecord method in Records. I found a FindRecord method in the PrimaryKeySortedRecords collection but it always returns -1. I stepped through the code and because the count is 0, this fn returns -1. What am I doing wrong? mainFrm.GroupingGrid.Table.PrimaryKeySortedRecords.FindRecord(txtNumber.Text); Thanks Shipra


AD Administrator Syncfusion Team March 21, 2005 08:18 PM UTC

Shipra, it could be that the column was not registered as a PrimaryKey column (in earlier versions that did not happen automatically). You can manually check by looking at TableDescriptor.PrimaryKeyColumns.Count. If Count is 0, you should manually add your column with TableDescriptor.PrimaryKeyColumns.Add(columnName); Stefan


SG Shipra Gupta March 21, 2005 10:55 PM UTC

Thanks for your reply. Now, that I have the row index, how do I scroll the view to that row in the grouping grid. For some reason, MoveTo doesn''t work (see code below). Thanks if(mainFrm.GroupingGrid.TableDescriptor.PrimaryKeyColumns.Count == 0) { mainFrm.GroupingGrid.TableDescriptor.PrimaryKeyColumns.Add("AnnouncementScenario"); } int i = mainFrm.GroupingGrid.Table.PrimaryKeySortedRecords.Count; int r = mainFrm.GroupingGrid.Table.PrimaryKeySortedRecords.FindRecord(txtScenarioNumber.Text); Syncfusion.Grouping.Record rec = mainFrm.GroupingGrid.Table.Records[r]; int rowIndexinGrid = mainFrm.GroupingGrid.Table.DisplayElements.IndexOf(rec); int colIndex = mainFrm.GroupingGrid.TableControl.CurrentCell.ColIndex; mainFrm.GroupingGrid.TableControl.CurrentCell.MoveTo(rowIndexinGrid, colIndex);


AD Administrator Syncfusion Team March 22, 2005 01:57 AM UTC

Try calling Record.SetCurrent(); Example: int r = mainFrm.GroupingGrid.Table.PrimaryKeySortedRecords.FindRecord(txtScenarioNumber.Text); if (r != -1) { Syncfusion.Grouping.Record rec = mainFrm.GroupingGrid.Table.Records[r]; rec.SetCurrent(); } Stefan >Thanks for your reply. Now, that I have the row index, how do I scroll the view to that row in the grouping grid. For some reason, MoveTo doesn''t work (see code below). > >Thanks > >if(mainFrm.GroupingGrid.TableDescriptor.PrimaryKeyColumns.Count == 0) >{ > mainFrm.GroupingGrid.TableDescriptor.PrimaryKeyColumns.Add("AnnouncementScenario"); >} > >int i = mainFrm.GroupingGrid.Table.PrimaryKeySortedRecords.Count; >int r = mainFrm.GroupingGrid.Table.PrimaryKeySortedRecords.FindRecord(txtScenarioNumber.Text); >Syncfusion.Grouping.Record rec = mainFrm.GroupingGrid.Table.Records[r]; >int rowIndexinGrid = mainFrm.GroupingGrid.Table.DisplayElements.IndexOf(rec); >int colIndex = mainFrm.GroupingGrid.TableControl.CurrentCell.ColIndex; >mainFrm.GroupingGrid.TableControl.CurrentCell.MoveTo(rowIndexinGrid, colIndex); >


SG Shipra Gupta March 22, 2005 04:49 PM UTC

Hello Stefan, I tried to do that but for some reason I get Object reference not set to an instance of an object error in CreateTableCellIdentity. Find attached .jpg file, which has the error message. Thanks Shipra untitled_913.zip


AD Administrator Syncfusion Team March 22, 2005 09:30 PM UTC

Hi Shipra, not sure why this happens. Can you enable "Break Into Exceptions" in the IDE and paste the call stack at the time of the exception and also what the row and column index is. Maybe it''s a bug in the version you have. Can you try with 3.x? Sorry about the inconvience. Stefan


SG Shipra Gupta March 23, 2005 12:00 AM UTC

Hello Stefan, Thanks for your reply. I found the problem, the issue was that the grid was not updated with the primary keys set. Appreciate all your help. Thank you Shipra


SG Shipra Gupta April 2, 2005 12:31 AM UTC

Hello Stefan, I think there is a problem with able.PrimaryKeySortedRecords.FindRecord function. Normally, it works great but if the user sorts the grid, by clicking on the column header (this column is also the primary key), the index returned by subsequent FindRecord function, points to the row index that was prior to the sort. Is it a known issue or am I doing something wrong? Please help Shipra


AD Administrator Syncfusion Team April 2, 2005 01:40 AM UTC

There are a couple of issues with PrimaryKeySortedRecords in 2.x that were fixed with 3.0. We ran into these issues when we worked on the ForeignKey support for 3.x. So with 3.x you should be fine. Stefan >Hello Stefan, > >I think there is a problem with able.PrimaryKeySortedRecords.FindRecord function. Normally, it works great but if the user sorts the grid, by clicking on the column header (this column is also the primary key), the index returned by subsequent FindRecord function, points to the row index that was prior to the sort. > >Is it a known issue or am I doing something wrong? Please help > >Shipra


SG Shipra Gupta April 5, 2005 08:53 PM UTC

Hello Stefan, Is there a workaround available/fix that can be used with version 2.1.0.50? Thanks Shipra


AD Administrator Syncfusion Team April 5, 2005 10:00 PM UTC

Unfortunately no. This is all tight closely with other changes we made for 3.x. Is there any way you can upgrade to 3.x? If you wait a couple of days you could try it with the 3.2 version. Do you have source code? If yes I could try and find out what changes in source code were made since then with regards to PrimaryKeys. Stefan >Hello Stefan, > >Is there a workaround available/fix that can be used with version 2.1.0.50? > >Thanks >Shipra


SG Shipra Gupta April 5, 2005 10:11 PM UTC

No, my manager doesn''t really want to upgrade at this point. Yes, we have the source code. It will be great if you can find out the changes in source code with regard to Primary keys. Moreover, if you can point, what internal data structures to change when user clicks on the column header to sort, that will be great. Thanks Shipra


SG Shipra Gupta May 20, 2005 12:04 AM UTC

Hello Stefan, As per our last conversation, can you please indicate what changes in source code were made in recent versions with regards to PrimaryKeys. Thanks Shipra Gupta


AD Administrator Syncfusion Team May 22, 2005 06:40 PM UTC

Shipra, sorry for the delay. I did extract both the 2.0.50 and 3.x source code and did a line to line comparison but couldn''t really identify those lines that will help you. I wanted to look at it again but then forgot ... I checked it again now but still no better luck. So the best is if I debug ino the problem in the 2.0 source code. I created a sample project in order to reproduce the problem but it seemed fine there. Can you look at the sample project and modify it such that it will demonstrate the problem you have. I will then be able o debug into it with the old 2.0 code base. This is the project: GroupCustomers2.zip Thanks, Stefan


SG Shipra Gupta June 11, 2005 12:18 AM UTC

Hello Stefan, Thanks for your reply. I can''t open the VC++ .NET solution file you sent. I get the error ''Unable to read the project file ''Syncfusion.Shared.2003.csproj''. The system cannot find the path specified. I get this error for - Syncfusion.Grouping.2003.csproj - Syncfusion.Grid.2003.csproj - Syncfusion.Grid.Grouping.2003.csproj Thanks Shipra


AD Administrator Syncfusion Team June 11, 2005 08:37 AM UTC

The files that Stefan attached are C# files, not C++. Try deleting the sln file and just open csprog file.


SG Shipra Gupta June 15, 2005 12:36 AM UTC

Hello Stefan, Find attached the modified example that illustrates the problem. Comments are embeded in the files. Let me know if you need more info. Thanks Shipra GroupCustomers2_8616.zip


AD Administrator Syncfusion Team June 16, 2005 03:43 PM UTC

Hi Shipra, a quick update: I see the problem you mentioned and will get back to you later this week once I found a workaround/solution. Stefan >Hello Stefan, > >Find attached the modified example that illustrates the problem. Comments are embeded in the files. Let me know if you need more info. > >Thanks >Shipra > > >GroupCustomers2_8616.zip > >


AD Administrator Syncfusion Team June 17, 2005 09:03 PM UTC

Hi Shipra, I found a mistake in your code. See comments in the following code snippet. I commented out your original code and added code for correct usage: private void menuItem1_Click(object sender, System.EventArgs e) { /* I think the record returned this way is correct, but the as the primary key * is composite, how do you sort on more than one key */ // Record r = this.groupingGrid1.Table.PrimaryKeySortedRecords["FAMIA"]; // r.SetCurrent(); // MessageBox.Show(this.groupingGrid1.Table.Records.IndexOf(r) + r.ToString()); /* The following is the code I have that returns the wrong index i.e. the current * index is not set to FAMIA */ // This code is wrong: // First it gets index in PrimaryKeySortedRecords // int idx = this.groupingGrid1.Table.PrimaryKeySortedRecords.FindRecord("FAMIA"); // Then it gets record at sorted positon (Table.Records is sorted by SortedColumns collection). // Syncfusion.Grouping.Record rec = this.groupingGrid1.Table.Records[idx]; // Here is what you should do: // int idx = this.groupingGrid1.Table.PrimaryKeySortedRecords.FindRecord("FAMIA"); // Syncfusion.Grouping.Record rec = this.groupingGrid1.Table.PrimaryKeySortedRecords[idx]; // or Record rec = this.groupingGrid1.Table.PrimaryKeySortedRecords["FAMIA"]; // int idx = this.groupingGrid1.Table.Records.IndexOf(rec); // gets position in sorted records if you need that rec.SetCurrent(); } Stefan


SG Shipra Gupta June 28, 2005 12:13 AM UTC

Thanks Stefan for your help. After the changes you mentioned, it works great. Shipra

Loader.
Up arrow icon