Preventing user from typing in a datagrid cell ?

Hi,

I have a normal vb.net datagrid. I do not want the user to enter any value in the first column of the grid. At the same time I cannot set it to readonly= true for some reason. How can I prevent the user from entering any value into the cells of only that column

The keypress or keydown events of the datagrid are not working. Can you please help me.

Prasad



Answer this question

Preventing user from typing in a datagrid cell ?

  • MikeBo

    Actually found an even better way.

    Select your DataGridView control in VS.NET 2005, then go to the property sheet.

    Next find the Columns collection under the Misc section.

    Click on the (Collection) property and click the button with the ...

    This will let you set Readonly property for each individual column, I tested this out and it works.



  • LwnChina

    First, I think it's not so normal datagrid if you expect it to be readonly but can't set it as readonly.

    Instead of KeyPress or KeyDown, have you tried looking into other events The following is copied from MSDN.

    Besides the common control events such as MouseDown, Enter, and Scroll, the DataGrid control supports events associated with editing and navigation within the grid. The CurrentCell property determines which cell is selected. The CurrentCellChanged event is raised when the user navigates to a new cell. When the user navigates to a new table through parent/child relations, the Navigate event is raised. The BackButtonClick event is raised when the user clicks the back button when the user is viewing a child table, and the ShowParentDetailsButtonClick event is raised when the show/hide parent rows icon is clicked.



  • Stefnany

    Another possible way to make a column read only is to add a calculated column to the dataset with expression =[SomeWriteableField]. Then display this as the first column and hide the real column (don't display real column in DataGrid.

  • Preventing user from typing in a datagrid cell ?