如何在 Windows 应用程序中只允许编辑 datagridview 中的特定列? [英] How do I allow edit only a particular column in datagridview in windows application?

查看:18
本文介绍了如何在 Windows 应用程序中只允许编辑 datagridview 中的特定列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在 DataGridview 中启用两列才能进行编辑.其他人不应被允许编辑.此外,我没有直接链接到数据源;我会做这样的事情

I want to enable only two columns in the DataGridview to be able to edit. The others should not be allowed to edit. Further I am not directly linking to datasource; I will be doing some thing like this way

DataTable dt = new DataTable();
dt.Columns.Add("Email");
dt.Columns.Add("email1");
for (int i = 0; i < 5; i++)
{
    DataRow dr = dt.NewRow();
    dr["Email"] = i.ToString();
    dr["email1"] = i.ToString() + "sdf";
    dt.Rows.Add(dr);
}
BindingSource bs = new BindingSource();
bs.DataSource = dt;
dataGridView1.DataSource = bs;

那么我应该设置哪个属性,这将只允许一列说电子邮件(在上面的例子中)是可编辑的.

So which property should I set, that will enable only one column say Email(in the above eg) to be editable.

推荐答案

将其他列的 ReadOnly 属性设置为 true.

Set the ReadOnly property of the other columns to true.

(您可能需要遍历 Columns 集合并使用 if 语句)

(You'll probably need to loop through the Columns collection and use an if statement)

这篇关于如何在 Windows 应用程序中只允许编辑 datagridview 中的特定列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆