There must be a validation in silverlight's DataGrid
element: if specific value is selected in combo-box, check-box column on the same row (DataGridCheckBoxColumn
) must be disabled. However, from what I see, I can disable only the entire column, which is unacceptable.
So, how do I disable a particular cell if I have its coordinates (row, column)?
P.S. Similar question - here doesn't suit for me. There are no CellEnter and CellLeave events in silverlight 4.
Answer: 1
You can do it in two ways. If you know the column number of the check box then you can hide it by specifying it as
Datagrid1.Columns[0].visibility = visibility.Collapsed;
Otherwise add a cell template for the check box and the other column, on enter the other column you maintain a status enabled as boolean. add a dropdownopened event for the combo box, in the event you can check the condition and make the status as enabled or disabled.
by : Sajeetharanhttp://stackoverflow.com/users/1749403Answer: 2
A part of the answer may be:
private void DisableCheckboxColumnInRow(DataGridRow row) { var checkBoxColumn = Datagrid1.Columns[0]; var checkBoxCell = GetCell(checkBoxColumn, row); checkBoxCell.IsEnabled = false; } private static DataGridCell GetCell(DataGridColumn column, DataGridRow row) { var cellContent = column.GetCellContent(row); return (DataGridCell)cellContent.Parent; }
But there may me a better way to do this using MVVM:
ViewModel part:
public class TestItem : INotifyPropertyChanged { private bool _isChecked; public bool IsChecked { get { return _isChecked; } set { _isChecked = value; OnPropertyChanged("IsChecked"); } } private bool _canBeChecked; public bool CanBeChecked { get { return _canBeChecked; } private set { _canBeChecked = value; OnPropertyChanged("CanBeChecked"); } } private string _selectedValue; public string SelectedValue { get { return _selectedValue; } set { _selectedValue = value; OnPropertyChanged("SelectedValue"); // here we do the 'magic': CanBeChecked = SelectedValue != "one"; } } public IEnumerable<string> PossibleValues { get { yield return "one"; yield return "two"; yield return "free"; } } #region Implementation of INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { var handler = PropertyChanged; if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName)); }
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog