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.

Getting Filtered Records collection in GGC

Thread ID:

Created:

Updated:

Platform:

Replies:

59255 Apr 9,2007 12:45 PM Sep 16,2008 05:11 AM Windows Forms 10
loading
Tags: GridControl
Vinod
Asked On April 9, 2007 12:45 PM

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


Administrator [Syncfusion]
Replied On April 9, 2007 08:57 PM

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

Vinod
Replied On April 10, 2007 08:26 AM

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

Administrator [Syncfusion]
Replied On April 10, 2007 10:37 AM

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?

Vinod
Replied On April 10, 2007 10:52 AM

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.

Administrator [Syncfusion]
Replied On April 10, 2007 11:33 AM

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



Vinod
Replied On April 13, 2007 02:23 PM

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

Administrator [Syncfusion]
Replied On September 15, 2008 11:46 PM

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


Administrator [Syncfusion]
Replied On September 16, 2008 02:12 AM

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?




Jisha Joy [Syncfusion]
Replied On September 16, 2008 02:39 AM

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


Administrator [Syncfusion]
Replied On September 16, 2008 05:11 AM

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?


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.

;