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.)
Hello,
I have been looking into your explanations and it seems that you want to create complex object bindings using our XamGrid. I can suggest you look into the following blog from our online community where it is provided an approach on how to achieve it :
http://es.infragistics.com/community/blogs/devin_rader/archive/2009/10/28/using-complex-object-bindings-in-xamwebgrid.aspx
Please note that the XamWebGrid is the previous name of XamGrid.
Let me know, if you need any further assistance on this matter.
Yes, this is what I need, but the problem is - as I said - I need some basic styling for the cell depending on property values in CellElement.
(for instance: bold the text if CellElement.Something=True)
This is why we don't use nested binding that you described.
Is there anything we can do ?
Hi,
Thank you for your reply. I set the ‘columnNumber’ variable to “this.MyGrid.Columns.IndexOf(e.Cell.Column) + 9” because you use the columns in the XamGrid from the 9th position :
for(var index = 9; index<RowObject.NumberOfColumns; index++) {
MyGrid.Columns.Add(new TextColumn() {
Key = string.Format("[{0}].Value", index), // which way to go ?
HeaderText = string.Format("[{0}]", index) // which way to go ?
});
}
You might skip the value check statement and use the following ‘if’ :
if (MyItems[rowNumber][columnNumber].SomeProperty1)
{
e.Cell.Control.Background = Brushes.Red;
e.Cell.Control.Foreground = Brushes.Yellow;
I have use it with test purpose.
Let me know, if you need any further assistance on this.
Thanks a lot.
I've missed the 9 in the loop, sorry.
Just last question: this idea that I can use index of row and column - will that break if:
- user clicks on the column header to sort the data
- user reorder some columns
- user hides some columns
- user setup some columns as Fixed columns
- user filters the data
?
Thank you for your feedback. I have been looking into your requirements and instead of accessing your data source directly, you could get the underlying data of a particular row and access the CellObject via the column’s key like e.g. :
private void MyGrid_CellControlAttached(object sender, CellControlAttachedEventArgs e)
RowObject test = e.Cell.Row.Data as RowObject;
string[] test1 = e.Cell.Column.Key.Split(new char[] { '[', ']'});
if(test[Convert.ToInt32(test1[1])].SomeProperty1)
else
e.Cell.Control.Background = Brushes.Transparent;
e.Cell.Control.Foreground = Brushes.Black;
Let me know, if you have any other questions on this matter.
Thanks a lot !
I think this is what we need.
Hello Lukas,
Thank you for your feedback. I am glad that you have managed to solve your issue.