I have a DataGridView with properties DataSource = datatable()
and readonly = false
. readonly
must be false since there are other columns that can be editable. How do I make all the columns in DataSource read only (not editable)?
The code is as follows:
type = new DataGridViewComboBoxColumn();
table= new DataGridView
{
DataSource = datatable(), // this returns a DataTable object
AllowUserToAddRows = false,
AllowUserToDeleteRows = false,
RowHeadersVisible = false,
MultiSelect = false,
Name = "AgentTable",
AutoSize = true,
ReadOnly = false,
};
table.Columns.Add(CreateStartButton());
type.Items.Add(" some table");
type.ReadOnly = false;
table.Columns.Add(type);
EDIT: the datagridview will contain 4 columns.
so my question is how to make the third and forth column read-only?
It should be easy to iterate the columns after you create them all. I'd use something like this, but I'm calling it pseudocode because I don't know if DataColumn is the correct data type:
foreach(DataColumn col in table.Columns) {
col.ReadOnly = true;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.