Datagrid column IsReadOnly property not working in Silverlight 4?


I'm currently working on a DataGrid which in some conditions should disable or enable particular columns by changing IsReadOnly to true and vice versa. I attached to CurrentCellChanged and CellEditEnded events in which I change the column IsReadOnly property. I expect the application to disable / enable edit on that column. Even though the column has IsReadOnly set to true sometimes it does allow edits. I've also tried to call CancelEdit(); on a grid but that didn't make any effect either. If you request I can post code but I'm pretty sure the logic is fine, I checked it like thousands of times in debug ;). The entire idea is nothing more than changing IsReadOnly of particular column in event. Any idea what why it's not working as I expect?

<strong>Edit1.</strong> Code added.

private void SrfDataGrid_CurrentCellChanged(object sender, EventArgs e) { CellCoordinates cellCoordinates = this.GetEditedCellCoordinates(); if (!this.LockDataGridCell(cellCoordinates)) { if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control) && !Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) this.srfDataGrid.BeginEdit(); } else { this.srfDataGrid.CancelEdit(); } } private void SrfDataGrid_CellEditEnded(object sender, DataGridCellEditEndedEventArgs e) { CellCoordinates cellCoordinates = this.GetEditedCellCoordinates(); this.SetCellsRowInfluence(cellCoordinates); this.UnlockDataGridCell(cellCoordinates); } public bool LockDataGridCell(CellCoordinates cellCoordinates) { bool result = false; if (cellCoordinates != null) { DataGridColumn currentColumn = this.srfDataGrid.CurrentColumn; if (this.spreadSheetCellState[cellCoordinates.ColumnName, cellCoordinates.RowID].Equals(CurrentCellState.WRITE)) { currentColumn.IsReadOnly = false; } else { currentColumn.IsReadOnly = true; } result = currentColumn.IsReadOnly; } return result; } public void UnlockDataGridCell(CellCoordinates cellCoordinates) { if (cellCoordinates != null) { DataGridColumn currentColumn = this.srfDataGrid.CurrentColumn; if (this.spreadSheetCellState[cellCoordinates.ColumnName, cellCoordinates.RowID].Equals(CurrentCellState.ALWAYS_READ_ONLY)) { currentColumn.IsReadOnly = true; } else { currentColumn.IsReadOnly = false; } } }


Try this:

foreach (DataGridColumn col in dataGrid1.Columns) { if (col.GetType() == typeof(DataGridTextColumn)) { col.IsReadOnly = true; } else { col.IsReadOnly = false; } }


  • JavaFX editable ComboBox in a table view
  • CancelEdit does not keep focus on edited cell in DataGridView c#
  • Why does SelectList SelectedValue work on HttpGet but not on HttpPost?
  • Modifying resource contents of a running executable
  • displaying markdown in my textarea
  • Avoid Inheriting Super Class Tests in ScalaTest
  • CKeditor stripping font tags instead of converting to span
  • Programatically open file in visual studio
  • Ionic Slide Up Slide Down Animation for only one view in sidebar
  • A new chart every sheet
  • LESS CSS how to modify parent property in mixin
  • C# - Most efficient way to iterate through multiple arrays/list
  • netsh acl setting (need alternative method - registry settings?)
  • Prevent Tomcat from caching request during starup
  • RxJava debounce by arbitrary value
  • Remove final comma from string in vb.net
  • onBackPressed() not being executed
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Symfony2: How to get request parameter
  • ActionScript 2 vs ActionScript 3 performance
  • How can I estimate amount of memory left with calling System.gc()?
  • log4net write single file for each call to log.info
  • python regex in pyparsing
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • Getting error when using KSoap library to consume .NET web services
  • Hits per day in Google Big Query
  • Why joiner is not used after Sequence generator or Update statergy
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Memory offsets in inline assembly
  • Change div Background jquery
  • Turn off referential integrity in Derby? is it possible?
  • How does Linux kernel interrupt the application?
  • How can I remove ASP.NET Designer.cs files?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?
  • java string with new operator and a literal
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize