I want to always disable and, if I can, clear the content of the first cell in the first row of my RadGridView. I know there is the readonly property to use, but that doesn't really work because then my objects need that field to bind to. It is static for me that in the first row, the first cell is always disabled. So no matter how the user moves around the rows or data, that cell remains static.
How can I do this?
5 Answers, 1 is accepted
You can achieve your requirement by setting the IsEnabled property of the GridViewCell to false. You can do that via the CellStyle property of the gridview column. You can see this approach shown in the attached project. I hope that helps.
Regards,
Martin Ivanov
Progress Telerik
Thanks for the example WPF project. I see how you are disabling the cell by criteria. I am still missing one piece of this. Within the converter you have, how do I check if the cell is the first cell in the grid? In pseudo code something like:
if(cell.row==0&&cell.column=0)
disable
else
don't disable it
If it helps, the reason I am doing this is I am creating a query builder. I don't want the And/Or dropdown column to appear in the first row of the grid because it wouldn't make sense. However, if a user re-ordered the rows, it would mean a different row could become the first row, which should immediate set the value of the cell to blank and disable it. So that is where I have been struggling is how do you identify in index of the cell in order to set it to read only? Could you tell me how or adjust the project to show me so the first cell in the grid is always blanked and disabled regardless of the data in it?
In my project I used the Id property to indicate if the cell is empty. You can try to implement this also on your side. For example, you can add a bool property that tells if the record is placed in the first row of the first column.
To get the cell's row and column without involving the view model, you can use the Items and Columns collections of the gridview. Here is an example in code:
public
class
GridViewCellToBoolConverter : IValueConverter
{
public
object
Convert(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
var cell = value
as
GridViewCell;
if
(cell !=
null
)
{
var data = (RowInfo)cell.DataContext;
var gridView = cell.DataColumn.DataControl;
var rowIndex = gridView.Items.IndexOf(data);
var columnIndex = cell.DataColumn.DisplayIndex;
if
(rowIndex == 0 && columnIndex == 0)
{
return
false
;
}
return
true
;
}
return
false
;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, CultureInfo culture)
{
throw
new
NotImplementedException();
}
}
Regards,
Martin Ivanov
Progress Telerik