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

finding a specific row in a grid

I would like to accomplish the following: A user specifies a certain row or range of rows they''d like to see highlighted in the grid based on a column name and a value for the specified column. For example - highlight all of the rows where column ''X'' = 25. Not only would I like to highlight the requested detail rows in the grid for the user based upon the user''s request, but I would like to be able to highlight summary rows in the grid based on the user''s request as well. Thank You.

11 Replies

AD Administrator Syncfusion Team December 7, 2004 04:03 PM

You can use conditional formats to color/format records. Here is code that displays any row where col2 > 5 with a special backcolor. GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("Col2GT5"); fd.Expression = "[Col2] > 5"; fd.Appearance.AnyCell.BackColor = Color.LightGoldenrodYellow; this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd); To handle any other special formating, I think you would have to handle the QueryCellStyleInfo event, and based and the information in e.TableCellIdentity, set e.Style as you desire.


AA Anthony Avella December 8, 2004 05:49 AM

My question pertains more to locating rows in a grid based on a specific value of a certain column - find all rows where the value of column ''X'' = "hello". How can I find both detail and summary rows based on the value of 1 column? >You can use conditional formats to color/format records. Here is code that displays any row where col2 > 5 with a special backcolor. > >GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("Col2GT5"); >fd.Expression = "[Col2] > 5"; >fd.Appearance.AnyCell.BackColor = Color.LightGoldenrodYellow; >this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd); > > >To handle any other special formating, I think you would have to handle the QueryCellStyleInfo event, and based and the information in e.TableCellIdentity, set e.Style as you desire.


AA Anthony Avella December 8, 2004 08:59 AM

Also, I want this locating of specific rows to be temporary - I don''t want anything to persist for the life of the grid. Once the user''s rows are found, the user should be able to click on another row and that row should be highlighted, with the grid having no memory of the previous search results. thanks >My question pertains more to locating rows in a grid based on a specific value of a certain column - find all rows where the value of column ''X'' = "hello". How can I find both detail and summary rows based on the value of 1 column? > > >>You can use conditional formats to color/format records. Here is code that displays any row where col2 > 5 with a special backcolor. >> >>GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("Col2GT5"); >>fd.Expression = "[Col2] > 5"; >>fd.Appearance.AnyCell.BackColor = Color.LightGoldenrodYellow; >>this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd); >> >> >>To handle any other special formating, I think you would have to handle the QueryCellStyleInfo event, and based and the information in e.TableCellIdentity, set e.Style as you desire.


AA Anthony Avella December 8, 2004 09:22 AM

Lastly, how would I format a GridConditionalFormatDescriptor to search for a string value in a column? colx = hello thanks >Also, I want this locating of specific rows to be temporary - I don''t want anything to persist for the life of the grid. Once the user''s rows are found, the user should be able to click on another row and that row should be highlighted, with the grid having no memory of the previous search results. > >thanks > >>My question pertains more to locating rows in a grid based on a specific value of a certain column - find all rows where the value of column ''X'' = "hello". How can I find both detail and summary rows based on the value of 1 column? >> >> >>>You can use conditional formats to color/format records. Here is code that displays any row where col2 > 5 with a special backcolor. >>> >>>GridConditionalFormatDescriptor fd = new GridConditionalFormatDescriptor("Col2GT5"); >>>fd.Expression = "[Col2] > 5"; >>>fd.Appearance.AnyCell.BackColor = Color.LightGoldenrodYellow; >>>this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(fd); >>> >>> >>>To handle any other special formating, I think you would have to handle the QueryCellStyleInfo event, and based and the information in e.TableCellIdentity, set e.Style as you desire.


AD Administrator Syncfusion Team December 8, 2004 09:43 AM

I still think ConditionalFormats would be the simplest way to handle this. When your user clicked on another row, you could just remove the conditional format (or clear the collection). In a groupinggrid, there is no facility to retrieve a set of records that satisfy a filter without you looping through the records yourself. Once you have these records, you would either have to add them to the Table.SelectedRecords (in the 3.0 code base) to see them selected. Or, you could handle QueryCellStyleInfo and color them using that event. If you use teh COnditionalFormat, you avoid these problems. All you have to do is to decide exactly what you want to use to trigger removing the ConditionalFormat. To mark the rowsummaries you want, you will have to handle QueryCellStyleInfo. If e.TableCellIdentity.DisplayElement is a GridSummaryRow you want to color, then set the e.Style.BackColor.


AA Anthony Avella December 8, 2004 11:35 AM

When you mention the 3.0 code base, are you referring to a new relase? Also, how do I format a filter for a column containing strings (see prev. question)? thx >I still think ConditionalFormats would be the simplest way to handle this. When your user clicked on another row, you could just remove the conditional format (or clear the collection). > >In a groupinggrid, there is no facility to retrieve a set of records that satisfy a filter without you looping through the records yourself. Once you have these records, you would either have to add them to the Table.SelectedRecords (in the 3.0 code base) to see them selected. Or, you could handle QueryCellStyleInfo and color them using that event. If you use teh COnditionalFormat, you avoid these problems. All you have to do is to decide exactly what you want to use to trigger removing the ConditionalFormat. > >To mark the rowsummaries you want, you will have to handle QueryCellStyleInfo. If e.TableCellIdentity.DisplayElement is a GridSummaryRow you want to color, then set the e.Style.BackColor.


AA Anthony Avella December 8, 2004 12:00 PM

Can you show me an example of looping through all of the records in the table to find the desired records? Assume I have a column name and a desired value to use as my criteria (column "name" = "John" for example ). >I still think ConditionalFormats would be the simplest way to handle this. When your user clicked on another row, you could just remove the conditional format (or clear the collection). > >In a groupinggrid, there is no facility to retrieve a set of records that satisfy a filter without you looping through the records yourself. Once you have these records, you would either have to add them to the Table.SelectedRecords (in the 3.0 code base) to see them selected. Or, you could handle QueryCellStyleInfo and color them using that event. If you use teh COnditionalFormat, you avoid these problems. All you have to do is to decide exactly what you want to use to trigger removing the ConditionalFormat. > >To mark the rowsummaries you want, you will have to handle QueryCellStyleInfo. If e.TableCellIdentity.DisplayElement is a GridSummaryRow you want to color, then set the e.Style.BackColor.


AD Administrator Syncfusion Team December 10, 2004 03:10 AM

//look for any record where Col1 starts with a "1"
foreach(Record r in this.gridGroupingControl1.Table.Records)
{
	string s = r.GetValue("Col1").ToString();
	if(s.StartsWith("1"))
		Console.WriteLine(s);
}


AA Anthony Avella December 10, 2004 05:37 AM

Thanks. Is 3.0 a new release of the grid? >
>//look for any record where Col1 starts with a "1"
>foreach(Record r in this.gridGroupingControl1.Table.Records)
>{
>	string s = r.GetValue("Col1").ToString();
>	if(s.StartsWith("1"))
>		Console.WriteLine(s);
>}
>


AA Anthony Avella December 10, 2004 06:29 AM

Also, how do I format a filter for a column containing strings (ex: colx = hello)? >
>//look for any record where Col1 starts with a "1"
>foreach(Record r in this.gridGroupingControl1.Table.Records)
>{
>	string s = r.GetValue("Col1").ToString();
>	if(s.StartsWith("1"))
>		Console.WriteLine(s);
>}
>


AD Administrator Syncfusion Team December 10, 2004 12:50 PM

Hi Anthony, 3.0 is a new version of Essential Suite. You can download a release candidate if you log into the customer support area. Or you can also contact sales to get download instructions. If you want to compare a specific column for a string, you can do this a) when looping through records: string s = r.GetValue("Col1").ToString(); if(s == "hello") Console.WriteLine(s); b) when specifying a filter: You use LIKE to work with strings (and bool values). You can also use match. The strings have to be in single quotes. // Filter with expression engine.TableDescriptor.RecordFilters.Clear(); RecordFilterDescriptor recordFilterDescriptor1 = new RecordFilterDescriptor(); recordFilterDescriptor1.Expression = "[Col1] LIKE ''hello''"; engine.TableDescriptor.RecordFilters.Add(recordFilterDescriptor1); // - or - // Filter with one condition engine.TableDescriptor.RecordFilters.Add("Col1", FilterCompareOperator.Like, "hello"); Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon