How we make Datagridview readonly.

Posted by Bageshkumarbagi under C# on 4/25/2013 | Points: 10 | Views : 1152 | Status : [Member] | Replies : 2
Hi ,
I want to make 3 column out of 4 as readonly and 4th column i want to make as editable. how can i do please any one help me.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Satyapriyanayak on: 4/25/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
dataGridView1.Columns[0].ReadOnly = true;

If this post helps you mark it as answer
Thanks

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nadeemshaik on: 5/1/2013 [Member] Starter | Points: 25

Up
0
Down
initally put datagridview readonly false

Datagridview1.Readonly = false;

if datagridview contains 4 columns
if you want to put the lastcolumn as readonly false and remaining columns readonly to true

then

for (int i = 0; i <= Datagridview1.Columns.Count - 1; i++)
{
if (i = 4)
{
DgIssueReceiptMain.Columns[i].ReadOnly = false;
}
else
{
DgIssueReceiptMain.Columns[i].ReadOnly = true;
}
}
---------------------------------------------

if you know the columns name then
for (int i = 0; i <= Datagridview1.Columns.Count - 1; i++)
{
if (Datagridview1.Columns[i].Name == "For Consumption")
{
Datagridview1.Columns[i].ReadOnly = false;
}
else if (Datagridview1.Columns[i].Name == "Must Return")
{
Datagridview1.Columns[i].ReadOnly = false;
}
else if (Datagridview1.Columns[i].Name == "Remarks")
{
Datagridview1.Columns[i].ReadOnly = false;
}
else if (Datagridview1.Columns[i].Name == "Quantity Issued")
{
Datagridview1.Columns[i].ReadOnly = false;
}
else
{
Datagridview1.Columns[i].ReadOnly = true;
}
}

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response