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

Getting Filtered Records collection in GGC

Hi,

I am using following code to highlight matching records (for the condition "Column1 = 1001") in GridGroupingControl.

Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor QuickFilterHighLiteParent = new Syncfusion.Windows.Forms.Grid.Grouping.GridConditionalFormatDescriptor();

QuickFilterHighLiteParent.Appearance.AnyRecordFieldCell.Interior = new Syncfusion.Drawing.BrushInfo(System.Drawing.Color.LightGreen);
QuickFilterHighLiteParent.Name = "ConditionalFormatHighLightParent";
this.dgRangePlanGrid.TableDescriptor.ConditionalFormats.Add(QuickFilterHighLiteParent);

dgRangePlanGrid.TableDescriptor.ConditionalFormats["ConditionalFormatHighLightParent"].RecordFilters.Add
(
new Syncfusion.Grouping.RecordFilterDescriptor("Column1", Syncfusion.Grouping.FilterLogicalOperator.Or,
new Syncfusion.Grouping.FilterCondition[] { new Syncfusion.Grouping.FilterCondition(Syncfusion.Grouping.FilterCompareOperator.Match, "1001") }));

This codes works fine.
How will I get the collection of these matching records?

Kindly reply ASAP.

Cheers,
Vinod


10 Replies

AD Administrator Syncfusion Team April 10, 2007 12:57 AM UTC

The this.gridGroupingControl1.Table.FilteredRecords collection should hold the currently displayed records in the GridGroupingCOntrol.


VI Vinod April 10, 2007 12:26 PM UTC

Hi Clay,

Thanks for the response.

But I don't want the collection of all records displayed in grid, but the collection of records matching the condition specified.

For e.g. Suppose there is a grid having two columns "Column1" and "Column2". There are total 10 records displayed in grid. Out of these 10 records, the value for 2 records in "Column1" is 555. I have highlighted these 2 matching records with the code mentioned in previous thread. Now I want to get the collection containing these 2 matching records.(for the condition "Column1" == 555)

Thanks,
Vinod


AD Administrator Syncfusion Team April 10, 2007 02:37 PM UTC

Once you have set a filter, then only the records that satisfy the filter are displayed in the grid. At that point, grid.table.FilteredRecords should hold the collection of records that are visible in the filtered grid (ie, the ones that satisfy your filter). When you check this collection after applying your filter, does it not show what you want?


VI Vinod April 10, 2007 02:52 PM UTC

If you see the code that I provided, I am not filtering data but just highlighting matching records using "GridConditionalFormatDescriptor" and "RecordFilters".

So if there are toatal 10 records and if 2 records match the condition mentioned in "RecordFilter", then all 10 records are displayed, but those matching 2 records are highlighted to indicate match.


AD Administrator Syncfusion Team April 10, 2007 03:33 PM UTC

Sorry, I missed that.

The grid has no 'collection' of records that satisfy a particular conditional format. The formatting for conditional formatting is determined on demand as the record is drawn in the grid.

So, if you want a collection of such records, then you would have to loop through all the current records in the grid and check the GridTableViewStyle to see if that particular record has the style applied to it. Here are some steps that show how this can be done.

1) This code sets up the formatting and additionally, puts a 1 in the Tag field of the row header cell.

GridConditionalFormatDescriptor gcfd = new GridConditionalFormatDescriptor();
gcfd.Expression = "[Col1] > [Col2]";
gcfd.Appearance.AnyCell.BackColor = Color.Red;
gcfd.Appearance.RowHeaderCell.Tag = 1; //mark the header cell
this.gridGroupingControl1.TableDescriptor.ConditionalFormats.Add(gcfd);


2) Here is a button handler that loops through all records in the grid to test whether this '1' value is set in the header cell. It simply points a particular field value in a listbox, but you could create an List or ArrayList of records that satisfy the filter.

private void button1_Click(object sender, EventArgs e)
{
foreach (GridRecord rec in gridGroupingControl1.Table.FilteredRecords)
{
int rowIndex = gridGroupingControl1.Table.DisplayElements.IndexOf(rec);
GridTableCellStyleInfo style = gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, 0); //0 is row header
if (style.Tag != null && style.Tag.Equals(1))
{
listBox1.Items.Add(rec.GetValue("Col0"));
}
}
}




VI Vinod April 13, 2007 06:23 PM UTC

Consider following code snippet in your previous reply:
private void button1_Click(object sender, EventArgs e)
{
foreach (GridRecord rec in gridGroupingControl1.Table.FilteredRecords)
{
int rowIndex = gridGroupingControl1.Table.DisplayElements.IndexOf(rec);
GridTableCellStyleInfo style = gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, 0); //0 is row header
if (style.Tag != null && style.Tag.Equals(1))
{
listBox1.Items.Add(rec.GetValue("Col0"));
}
}
}

1) There is no "FilteredRecords" collection in gridGroupingControl1.Table

2)What is second parameter in gridGroupingControl1.TableControl.GetTableViewStyleInfo(rowIndex, 0)?

Is it column index or row header? If it is row header, how will I get it's value?

Thanx,
Vinod


AD Administrator Syncfusion Team September 16, 2008 03:46 AM UTC

Can someone tell me how to highlight or to apply the format just on a particular column, NOT the entire row?



AD Administrator Syncfusion Team September 16, 2008 06:12 AM UTC

What I meant earlier on, how to apply the format just on a particular column depending on the record filter?

I tried:
GridConditionalFormatDescriptor gcfd = new GridConditionalFormatDescriptor("gcfd"); _gridClaims.TableDescriptor.Columns["_colAmount"].TableDescriptor.ConditionalFormats.Add(gcfd); _gridClaims.TableDescriptor.Columns["_colAmount"].TableDescriptor.ConditionalFormats["gcfd"].Expression = "[Amount] like '-*'"; gcfd.TableDescriptor.Columns["_colAmount"].Appearance.AnyRecordFieldCell.TextColor = Color.Red;

And this would apply the format just on column "_colAmount" BUT diregarding the expression "[Amount] like '-*'".

And if I do:
GridConditionalFormatDescriptor gcfd = new GridConditionalFormatDescriptor("gcfd"); _gridClaims.TableDescriptor.Columns["_colAmount"].TableDescriptor.ConditionalFormats.Add(gcfd); _gridClaims.TableDescriptor.Columns["_colAmount"].TableDescriptor.ConditionalFormats["gcfd"].Expression = "[Amount] like '-*'";
_gridClaims.TableDescriptor.Columns["_colAmount"].TableDescriptor.ConditionalFormats["gcfd"].Appearance.RecordFieldCell.TextColor = Color.Red

This would apply the format on rows with column "[Amount] like '-*'", but the format applies to the WHOLE row, not just on column "_colAmount" :(


I need the format to be applied on rows satisfying the expression filter BUT only on column "_colAmount".



>Can someone tell me how to highlight or to apply the format just on a particular column, NOT the entire row?





JJ Jisha Joy Syncfusion Team September 16, 2008 06:39 AM UTC

Hi,


You cannot format a specified column using GridConditionalFormatDescriptor. GridConditionalFormatDescriptor only allow you to row formatting. If you intension is to format the cell of a specified column then you need to use QueryCellStyleInfo or PrepareViewStyleInfo event.
Please refer to the below code in which QueryCellStyleInfo event is used.

this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);




void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{

if (e.TableCellIdentity.ColIndex == 2 )
{
e.Style.BackColor = Color.Red;
}

}
}


Thanks,
Jisha



AD Administrator Syncfusion Team September 16, 2008 09:11 AM UTC

Hi Jisha,

Thank you so much for the prompt reply :)
I knew about the QueryCellStyleInfo, but I was hoping that it's also plausible using GridConditionalFormatDescriptor.
It's such a pity that it's not supported when formatting the entire row or a specified column for entire record is possible.
Maybe this can be a new feature in the future?


Loader.
Live Chat Icon For mobile
Up arrow icon