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.
Unfortunately, activation email could not send to your email. Please try again.

Find operation in grouping grid control

Thread ID:

Created:

Updated:

Platform:

Replies:

26305 Mar 18,2005 07:17 PM Jun 27,2005 08:13 PM Windows Forms 21
loading
Tags: Grouping
Shipra Gupta
Asked On March 18, 2005 07:17 PM

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

Administrator [Syncfusion]
Replied On March 19, 2005 02:35 PM

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 > >

Shipra Gupta
Replied On March 21, 2005 01:00 PM

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

Administrator [Syncfusion]
Replied On March 21, 2005 03:18 PM

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

Shipra Gupta
Replied On March 21, 2005 05:55 PM

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);

Administrator [Syncfusion]
Replied On March 21, 2005 08:57 PM

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); >

Shipra Gupta
Replied On March 22, 2005 11:49 AM

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

Administrator [Syncfusion]
Replied On March 22, 2005 04:30 PM

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

Shipra Gupta
Replied On March 22, 2005 07:00 PM

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

Shipra Gupta
Replied On April 1, 2005 07:31 PM

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

Administrator [Syncfusion]
Replied On April 1, 2005 08:40 PM

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

Shipra Gupta
Replied On April 5, 2005 04:53 PM

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

Administrator [Syncfusion]
Replied On April 5, 2005 06:00 PM

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

Shipra Gupta
Replied On April 5, 2005 06:11 PM

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

Shipra Gupta
Replied On May 19, 2005 08:04 PM

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

Administrator [Syncfusion]
Replied On May 22, 2005 02:40 PM

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

Shipra Gupta
Replied On June 10, 2005 08:18 PM

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

Administrator [Syncfusion]
Replied On June 11, 2005 04:37 AM

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

Shipra Gupta
Replied On June 14, 2005 08:36 PM

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

Administrator [Syncfusion]
Replied On June 16, 2005 11:43 AM

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 > >

Administrator [Syncfusion]
Replied On June 17, 2005 05:03 PM

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

Shipra Gupta
Replied On June 27, 2005 08:13 PM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;