Hello
We are using XamGrid , v 12.2.20122.2202
The problem we have is hard to explain, but let me try (in this case description will be better than sample app)
In our application we have a XamGrid that ItemsSource is bound to the collection of "RowElement" objects.There are thousands or RowElements.
Now, each RowElement has a collection of "CellElement" objects, there is - let say - about 50 of them.
CellElement has property "Value" - of type sys:double (and of course some other properties, not really relevant here).
The goal is that we generate all those 50 columns from code-behind so that each cell displays the "Value" property - and it's editable. (so if I double click the cell, I can edit it).
The issue is that, no matter how I set up the TextColumns, I cannot have such functionality.
Solution 1:
column.Key = "[index]" // where index is the index of column
In this case, Cell is bound to the "CellElement" object, and TextBlock displays only "namespace.CellElement" instead of Value (which is obvious)
Solution 2:
column.Key = "[index]"
column.ValueConverter = new MyConverter() // this simply converts CellElement to the CellElement.Value
Now it works with view, but I cannot edit, as underlying data is sys:double, and when edited - it doesn't know what was the CellElement
Solution 3:
column.Key = "[index].Value"
Same as before
Solution we currently use:
We have TemplateColumns instead of TextColumns, where the binding is set to "CellElement" and then data template do the rest.
The problem we have with TemplateColumns is that they make scrolling of the grid completely slow. This is because those DataTemplates are generated from code behind. With TextColumns the performance is remarkable - not even comparable with template columns - but there are those issues we cannot solve.
So there is this question: how to set up TextColumns to work as described?
(Note that we need CellElement objects, as there are some properties inside that drive Cell styling (colors and so on.)
Thank you Yanko !
This is exactly what I needed.
However, few things are not clear to my:
Why + 9 ?
If user change position of some columns, or make some columns as Fixed - would I have a problem ?
if (MyItems[rowNumber][columnNumber].Value == (double)e.Cell.Value && MyItems[rowNumber][columnNumber].SomeProperty1)
Why first condition ?
Hello,
Thank you for your reply. I have been looking into your sample application and it seems that the easiest way to style a cell depending on a property of the underlying data is handling the ‘CellControlAttached’ event of the XamGrid and do the needed checks like e.g. :
private void MyGrid_CellControlAttached(object sender, CellControlAttachedEventArgs e)
{
int rowNumber = e.Cell.Row.Index;
int columnNumber = this.MyGrid.Columns.IndexOf(e.Cell.Column) + 9;
e.Cell.Control.Background = Brushes.Red;
e.Cell.Control.Foreground = Brushes.Yellow;
//or apply CellControl style
//e.Cell.Style
}
I am attaching a modified version of your sample application(TextColumnNestedBindingModified.zip) that shows this approach.
Let me know, if you need any further assistance on this matter.
Ok, I've added sample application.
There are very straightforward comments inside.
(When you analise the application, please also double check my initial post to see what is the exact problem).
Thanks in advance!
Hi Lukasz,
Thank you for your feedback. I will wait for your sample application or you could modify my one.
Actually - no, because at CellStyle Triggers, the binding is set to whole row - and we cannot declare style for each column.
Please double check my initial description, - i will try to provide sample app next week.