当前位置:编程学习 > C#/ASP.NET >>

急啊,c# winform中的datagridview问题?

c# winform中的datagridview我通过查询SQL数据库返回的DATASET填充,填充后,datagridview的标题列就类似下面:

编号  姓名  性别


==========

现在问题是: 我在窗体中加入一个按钮,我在该按钮的click事件中如何写代码判断出 datagridview["姓名"] 的列索引为 1 呢?

大侠帮帮们呀 --------------------编程问答-------------------- private void button1_Click(object sender, EventArgs e)
{
foreach (DataGridViewColumn col in this.dataGridView1.Columns)
{
if (col.DataPropertyName=="姓名")
int tmpIndex = this.dataGridView1.Columns.IndexOf(col);
Console.WriteLine(tmpIndex);
}
} --------------------编程问答-------------------- 如上
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,