DataGrid and FlexGrid
-
I have a VC dialog that hosts a FlexGrid control. The contol has two columns with data. The first column has read only data and is fixed. So it has a 3D edge for each cell that looks like a button. The second column is editable. I'm porting this to C#. In the form I place a DataGrid to display the data. Two things I cannot do with DataGrid. First, I cannot get the 3D edge for the cells in column 1 and second, I cannot stop DataGrid from adding new rows. I just need to edit the contents of column 2 and not add more rows. Can somebody help ? « Superman »
-
I have a VC dialog that hosts a FlexGrid control. The contol has two columns with data. The first column has read only data and is fixed. So it has a 3D edge for each cell that looks like a button. The second column is editable. I'm porting this to C#. In the form I place a DataGrid to display the data. Two things I cannot do with DataGrid. First, I cannot get the 3D edge for the cells in column 1 and second, I cannot stop DataGrid from adding new rows. I just need to edit the contents of column 2 and not add more rows. Can somebody help ? « Superman »
To create custom columns, extend the
DataGridColumnStyle
and override the necessary methods. You could then paint whatever borders you want. There are many examples here on CodeProject, MSDN[^], and elsewhere (just google). To disallow new rows, you either need to bind to anIList
orIListSource
implementation that is fixed in size (like an array of objects), or bind to aDataView
instead of aDataSet
orDataTable
. Set theDataView.AllowNew
property totrue
when doing so. See the documentation for theDataView
class for more information and example code.Microsoft MVP, Visual C# My Articles
-
To create custom columns, extend the
DataGridColumnStyle
and override the necessary methods. You could then paint whatever borders you want. There are many examples here on CodeProject, MSDN[^], and elsewhere (just google). To disallow new rows, you either need to bind to anIList
orIListSource
implementation that is fixed in size (like an array of objects), or bind to aDataView
instead of aDataSet
orDataTable
. Set theDataView.AllowNew
property totrue
when doing so. See the documentation for theDataView
class for more information and example code.Microsoft MVP, Visual C# My Articles
Thanks Heath for you earlier reply. I could get what I wanted done. But I have another problem and thought maybe you could shed some light. The grid has 2 columns and 5 rows out of which one column is editable. I'm implementing an observer pattern where the grid is one of the views. When the user changes the text in the grid column I need to update the model. For this I register for the LostFocus event of the TextBox hosted in the DataGridTextBoxColumn. This is done in my derived class. Everything is allright if the user enters text and changes focus using the mouse. But using the arrow keys, the focus does change to the next grid cell, but there is no LostFocus event generated. « Superman »
-
Thanks Heath for you earlier reply. I could get what I wanted done. But I have another problem and thought maybe you could shed some light. The grid has 2 columns and 5 rows out of which one column is editable. I'm implementing an observer pattern where the grid is one of the views. When the user changes the text in the grid column I need to update the model. For this I register for the LostFocus event of the TextBox hosted in the DataGridTextBoxColumn. This is done in my derived class. Everything is allright if the user enters text and changes focus using the mouse. But using the arrow keys, the focus does change to the next grid cell, but there is no LostFocus event generated. « Superman »
When deriving your own classes, you can fire all the events you want. The
Commit
method is still called on the derived class so add an event to your class and fire it inside theCommit
implementation. It's your class - you have control of what happens.Microsoft MVP, Visual C# My Articles