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.
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(...);
I passed a valid DataRecord and Field to CellValuePresenter.FromRecordAndField, but it returned null value. What do you think might go wrong?
Can you provide a sample application so that we can look into it?
Attached is a sample application made by using your object data binding sample.
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?