I have a binded DataGridView that contains a large amount of data. The problem is that some cells has to be ReadOnly and also when the user navigates with TAB or ENTER betwe
I haven't tried this.
But, you could set the cell's readonly property to true (as per Rashmi), on RowEnter event?
I guess RowEnter event should fire when you move from one row to the other (or it should when you change from cell A1 to B3).
Does that help at all?
I iterated through the datagrid with the following code:
dataGridViewTest.DataSource = persons;
foreach (DataGridViewRow row in dataGridViewTest.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value.ToString() == "John")
{
cell.ReadOnly = true;
}
}
}
Could you not use a template column instead of a bound column then have a condition for the readonlyness of the field?
Then you could present a label for readonly and a textbox for editable. Labels would not interfere with your tab index.
<asp:TemplateColumn>
<ItemTemplate>
<%
if ( <%# Eval( "ReadOnlyFlag" ) %> )
{
%>
<asp:Label Text="<%# Eval( "BoundColumn" ) %>" />
<%
}
else
{
%>
<asp:Textbox Text="<%# Eval( "BoundColumn" ) %>" />
<%
}
%>
</ItemTemplate>
</asp:TemplateColumn>