Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
18636 | Sep 5,2004 09:50 AM UTC | Sep 10,2004 05:18 AM UTC | WinForms | 9 |
![]() |
Tags: Grouping |
TableDescriptor.Columns["City"].Apperance.AnyRecordFieldCell.BackColor = Color.Blue;
This will make the change appear for any cell of that column in the table.
If you want to change the appear of specific cells (e.g. based on some dynamic criteria) you can handle the QueryCellStyleInfo event instead e.g.
this.gridGroupingControl1.QueryCellStyleInfo += new Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
private void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
// Record
Record r = style.TableCellIdentity.DisplayElement.ParentRecord;
// Column
ColumnDescriptor column = style.TableCellIdentity.Column;
// Get Field
if (column != null
&& (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell))
{
object value = r.GetValue(column.FieldDescriptor);
if (value is someCriteria)
e.Style.BackColor = Color.Red;
// BTW - If you need record index or unsorted record index
int recordIndex = r.ParentTable.Records.IndexOf(r);
int unsortedrecordIndex = r.ParentTable.UnsortedRecords.IndexOf(r);
}
}
To hide a specific column, you can simple remove the column from the TableDescriptor.VisibleColumns collection.
If you want to highlight records on criteria check out also ConditionalFormats.
Stefan
///
/// PlusMinus cell in group caption
///
GroupCaptionPlusMinusCell,
///
/// Group caption cell
///
GroupCaptionCell,
///
/// Any cell in group header section.
///
The QueryCellStyleInfo will be called for each column in that row, so you can format the whole row.
But since you mentioned you are only interested in Group captions and not individual records ...
Another option you have is to get the group directly and then set its group.Appearance.GroupCaptionCell.BackColor or
group.Appearance.AnyCaptionCell.BackColor
The GroupCustomer sample shows how to get a reference to a specific group:
int index = this.groupingGrid1.Table.TopLevelGroup.Groups.FindGroup("Germany");
if (index != -1)
{
Group germanyGroup2 = this.groupingGrid1.Table.TopLevelGroup.Groups[index];
Trace.WriteLine(germanyGroup2);
}
// Now you can set appearance here.
Stefan
> ///
> /// PlusMinus cell in group caption
> ///
> GroupCaptionPlusMinusCell,
> ///
> /// Group caption cell
> ///
> GroupCaptionCell,
> ///
> /// Any cell in group header section.
> ///
>
>
>The QueryCellStyleInfo will be called for each column in that row, so you can format the whole row.
>
>But since you mentioned you are only interested in Group captions and not individual records ...
>
>Another option you have is to get the group directly and then set its group.Appearance.GroupCaptionCell.BackColor or
>group.Appearance.AnyCaptionCell.BackColor
>
>The GroupCustomer sample shows how to get a reference to a specific group:
>
>
> int index = this.groupingGrid1.Table.TopLevelGroup.Groups.FindGroup("Germany");
> if (index != -1)
> {
> Group germanyGroup2 = this.groupingGrid1.Table.TopLevelGroup.Groups[index];
> Trace.WriteLine(germanyGroup2);
> }
>
>// Now you can set appearance here.
>
>
>Stefan
>
>
>
// In your Forms ctor after calling InitializeComponent:
AutoSizeHeightOfGrid();
this.gridGroupingControl1.RecordExpanded += new RecordEventHandler(gridGroupingControl1_RecordExpanded);
this.gridGroupingControl1.RecordCollapsed += new RecordEventHandler(gridGroupingControl1_RecordCollapsed);
this.gridGroupingControl1.GroupExpanded += new GroupEventHandler(gridGroupingControl1_GroupExpanded);
this.gridGroupingControl1.GroupCollapsed += new GroupEventHandler(gridGroupingControl1_GroupCollapsed);
// Add these methods to form
private void gridGroupingControl1_RecordExpanded(object sender, RecordEventArgs e)
{
AutoSizeHeightOfGrid();
}
private void gridGroupingControl1_RecordCollapsed(object sender, RecordEventArgs e)
{
AutoSizeHeightOfGrid();
}
private void gridGroupingControl1_GroupExpanded(object sender, GroupEventArgs e)
{
AutoSizeHeightOfGrid();
}
private void gridGroupingControl1_GroupCollapsed(object sender, GroupEventArgs e)
{
AutoSizeHeightOfGrid();
}
void AutoSizeHeightOfGrid()
{
int height = (int) this.gridGroupingControl1.Table.GetYAmountCount();
height += SystemInformation.HorizontalScrollBarHeight;
height += 2; // Borders
this.gridGroupingControl1.Bounds = new Rectangle(10, 10, ClientSize.Width-20, height);
}
Stefan
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.
This page will automatically be redirected to the sign-in page in 10 seconds.