Gentian said:
I have a datagrid that I want to be able to allow me to edit only the
first two rows and all the other rows to be read-only.
Assuming the DataGrid in VS2003 works the same as in VS2005 (I don't know
whether it does or not, I only have VS2005 installed), you should be able to
achieve this by:
- declaring a class that inherits from Windows.Forms.DataGridTextBoxColumn
- in the class, override the Edit method. Add code that calls into the base
class if the rowNum is one you want to be editable, or simply returns
without doing anything if you want the column to be read-only.
- when initialising the grid, create a new Windows.Forms.DataGridTableStyle
object.
- for each column in the grid, add a new instance of your class from above
to the DataGridTableStyle object. Make sure you set the MappingName property
of the object to match the underlying column name in your DataTable, and
also set the HeaderText, Width, Alignment and anything else you need.
- once you've added all your columns, add the DataGridTableStyle object to
the DataGrid.TableStyles collection.
- finally, set the DataGrid's DataSource.
Hopefully that will do what you want!