将"隐藏(或元)"列添加到不会在绑定的DataGridView中显示的DataTable中

Adding “hidden (or meta)” column to DataTable that will not be displayed in the bound DataGridView
2021-07-31
  •  译文(汉语)
  •  原文(英语)

我正在dgv使用Windows窗体的DataGridView .在dgv绑定到数据表dt作为它的数据源.

dgv.DataSource = dt;

为了有效地定位特定行,我需要在中有一id (int)dt.但是,由于ID对用户没有用,所以我想在中隐藏整个id列,dgv这样用户甚至都不知道有id列.我该怎么办?如果不可能,是否还有其他解决方法?我正在使用VS C#Express 2010

解决过程1

更改您的DataGridViewColumn的Visible属性.

来自msdn:

// Hide a band of cells. 
private void Button6_Click(object sender, System.EventArgs e)
{

    DataGridViewBand band = dataGridView.Rows[3];
    band.Visible = false;
}
速聊1:
谢谢!像魅力一样工作

I'm working on a DataGridView dgv in a Windows form. The dgv is bound to a DataTable dt as its datasource.

dgv.DataSource = dt;

In order to efficiently locate a particular row, I need to have a id (int) column in dt. However, since an ID has no use to a user, I would like to hide the entire id column in the dgv so the user won't even know there is an id column. How should I do that? If that's not possible, is there any other work around? I'm using VS C# Express 2010

Solutions1

Change the Visible property of your DataGridViewColumn.

From msdn:

// Hide a band of cells. 
private void Button6_Click(object sender, System.EventArgs e)
{

    DataGridViewBand band = dataGridView.Rows[3];
    band.Visible = false;
}
Talk1:
Thanks! Work like a charm
转载于:https://stackoverflow.com/questions/17087989/adding-hidden-or-meta-column-to-datatable-that-will-not-be-displayed-in-the

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入