Home › Forums › WPF controls › Xceed DataGrid for WPF › read only properties
-
AuthorPosts
-
#23462 |
Can a column contain public properties that are read only? ie that only have a getter, and not a setter?
My initial try resulted in an invalidoperation exception; “A TwoWay or OneWayToSource binding cannot work on the read-only property…”
I’d rather these properties remain read only, but still be displayed in the grid. I thought I’d set the cell to ReadOnly, but that doesnt help.
Is there another way around this?
thanks
Imported from legacy forums. Posted by Jack (had 3597 views)
you can set the Column.ReadOnly property to “True”. This should prevent edition (and binding created should reflect htat).
Imported from legacy forums. Posted by Marcus [Xceed] (had 294 views)
Hi,
I am setting the col to ReadOnly, but I continue to get that exception.
Here’s in most of my code;
private void BindGrid()
{
// clear grid first
ResetGrid(false, true);if (events == null) return;
DataGridCollectionView temp = new DataGridCollectionView(events);
temp.ItemProperties.Clear();
temp.ItemProperties.Add(new DataGridItemProperty(“EventID”, “EventID”, typeof(Guid)));
temp.ItemProperties.Add(new DataGridItemProperty(“EventType”, “EventType”, typeof(string)));
temp.ItemProperties.Add(new DataGridItemProperty(“SmartIDFull”, “SmartIDFull”, typeof(string)));
temp.ItemProperties.Add(new DataGridItemProperty(“Status”, “Status”, typeof(string)));
temp.ItemProperties.Add(new DataGridItemProperty(“EventDate”, “EventDate”, typeof(string)));
temp.ItemProperties.Add(new DataGridItemProperty(“TotalNett”, “TotalNett”, typeof(decimal)));
temp.ItemProperties.Add(new DataGridItemProperty(“TotalGST”, “TotalGST”, typeof(decimal)));
temp.ItemProperties.Add(new DataGridItemProperty(“Total”, “Total”, typeof(decimal)));grid.ItemsSource = temp;
// read only cols
grid.Columns[“EventID”].ReadOnly = true;
grid.Columns[“EventType”].ReadOnly = true;
grid.Columns[“SmartIDFull”].ReadOnly = true;
grid.Columns[“Status”].ReadOnly = true;
grid.Columns[“EventDate”].ReadOnly = true;
grid.Columns[“TotalNett”].ReadOnly = true;
grid.Columns[“TotalGST”].ReadOnly = true;
grid.Columns[“Total”].ReadOnly = true;}
re: DataGridCollectionView temp = new DataGridCollectionView(events);
events is an IBindingList of objects, and these objects *only* have read-only properties.
If anyone here has successfully bound to read-only properties, or knows of a sample, could they please let me know?
Imported from legacy forums. Posted by Jack (had 683 views)
I’ve noticed that this exception only occurs when I try to add the ItemProperties manually, like this;
DataGridCollectionView temp = new DataGridCollectionView(events);
temp.ItemProperties.Clear();
temp.ItemProperties.Add(new DataGridItemProperty(“EventID”, “EventID”, typeof(Guid)));
grid.ItemsSource = temp;If I do it like this;
DataGridCollectionView temp = new DataGridCollectionView(events);
grid.ItemsSource = temp;everything works fine
Imported from legacy forums. Posted by Jack (had 619 views)
Thank you, we’ll take a look at this, considering this additional information.
Imported from legacy forums. Posted by Marcus [Xceed] (had 4461 views)
-
AuthorPosts
- You must be logged in to reply to this topic.