Is there any way to change cell or column background or foreground colours?
You can see an example of conditional formatting here:
http://blogs.infragistics.com/blogs/alex_fidanov/archive/2010/01/12/howto-using-wpf-converters-to-style-the-xamdatagrid.aspx
How could I select a cell dynamically in c# code and change the background colour of that cell?
For example, I want to select a cell at row 6 and column 5, and then change the background colour of that cell to red.
I am new to the datagrid control. Thank you for answering my questions.
Could any one confirm with me if it is possible to select a cell dynamically (how to select?) in c# code and change the background or foreground colour of that cell (how to change?), after the datagrid is displayed?
If yes, could any one tell me how to do it or show an example? If no, could I ask this as a new feature for the next release of the datagrid.
This functionality is very important to my project. Please DO reply my question, even the answer is no!
Many thanks.
If you want to select a cell in procedural code, you can set the IsSelected property of that cell.
If you want to change the background of a cell in procedural code, you have to get the CelLValuePresenter for that cell with the following line:
CellValuePresenter.FromCell(...); and then set the background of that presenter.
However, this color will not be persistet when the cell is scroll out and then back into view, because of the virtualization techniques as the CVP is being destroyed and then recreated.
For this, you can create a style for the CVP and control this with trigger (for the IsSelected property) and change the background.
Thanks. Before I set the IsSelected property of a cell, how could I locate to that cell in procedural code? Is there any example to select a cell like this cell[5][6] (5 is the row number, 6 is the column number)?
Yes,
Then you can use the other static method of the CellValuePresenter:
CellValuePresenter.FromRecordAndField(...);
Hi WPFDEV,
You can do this in xaml as well by defining a style and on event trigger change the background red
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="SelectedCellStyle">
>
="True" >
="Red"/>
Sorry,
I haven't looked at it, it appears it got lost among the other forum threads.
The code that you are using is executed too early. The CVP is not generated yet. You can use this code as early as the Loaded event of the XamDataGrid when CellValuePresenters are generated.
31 void XamDataGrid1_Loaded(object sender, RoutedEventArgs e)
32 {
33 DataRecord dataRecord = (DataRecord)this.XamDataGrid1.Records[1];
34
35 Infragistics.Windows.DataPresenter.Field field = dataRecord.FieldLayout.Fields[1];
36 CellValuePresenter cellValuePresenter = CellValuePresenter.FromRecordAndField(dataRecord, field);
37
38 if (cellValuePresenter != null)
39 cellValuePresenter.Value = "Some car";
40 }
Hi Alex, did you have a chance to have a look at the sample I sent to you last week?
Attached is a sample application made by using your object data binding sample.
Can you provide a sample application so that we can look into it?