System.Windows.Forms.DataGrid question.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everyone.
Normally, the cell of the System.Windows.Forms.DataGrid could be inputed.
How can I let the cells only show something and not be inputed?
 
Hi Steven,

The DataGrid doesn't have that kind of control, but a DataView does. Assuming you use the first DataTable in a DataSet called 'ds'

ds.Tables[0].DefaultView.AllowNew = false;
ds.Tables[0].DefaultView.AllowEdit = false;

AllowNew set to false prevents the blank new line at the bottom.
 
Steven.Xu said:
Hello everyone.
Normally, the cell of the System.Windows.Forms.DataGrid could be inputed.
How can I let the cells only show something and not be inputed?

by using DataGridTableStyles you can make individual columns read only
 
You can control that by DataGridColumnStyle, you can reach a specific column
style object and control its readonly property:

yourGrid.TableStyles["TableName"].GridColumnStyles["ColumnName"].ReadOnly =
true;

or you can higher control when you access the TextBox control hosted in the
cell, accessing a TextBox properties of a cell will be like this:

((DataGridTextBoxColumn)(this.yourGrid.TableStyles["TableName"].GridColumnStyles[""])).TextBox.ReadOnly = true;

Note: To reach the text box, you reach first the ColumnStyle object and cast
it to DataGridTextBoxColumn refrence to be able to access "TextBox" property
that allows you to control the textbox objects hosted in that column cells.

Hope that work with you, good luck
 
Back
Top