[英]Hide id column from datagridview but need to use it
I want to hide id column from datagridview. 我想从datagridview隐藏id列。 I tried by changing stored procedure / SQL query, it works but I was unable to get id of that entry for some reason I also need id of each entry but don't want to show on front end.
我尝试通过更改存储过程/ SQL查询来解决问题,但是它由于某些原因而无法获取该条目的ID,我也需要每个条目的ID但又不想在前端显示。
Any suggestions, please? 有什么建议吗?
private void category_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'shopBillingDataSet.category' table. You can move, or remove it, as needed.
this.categoryTableAdapter.Fill(this.shopBillingDataSet.category);
button3.Enabled = false;
button1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
BSL.category obj = new BSL.category();
obj.catName = textBox1.Text;
obj.catDesc = textBox2.Text;
DAL.categoryDAL obj1 = new categoryDAL();
obj1.addCategory(obj);
this.categoryTableAdapter.Fill(this.shopBillingDataSet.category);
textBox1.Text = "";
textBox2.Text = "";
MessageBox.Show("New Category entered");
category_Load(sender,e);
}
As comment says, you can do this: 如评论所述,您可以执行以下操作:
dgName.Columns[i].Visible = false;
Or if you are binding to a class, you can set a custom attribute on the data value, something like this: 或者,如果要绑定到类,则可以在数据值上设置自定义属性,如下所示:
public class Row {
[Browsable(false)]
public int Id {get;set;}
public string Name {get;set;}
}
//dgName.DataSource = new BindingList<Row>();
*edit: obviously you wouldn't want to bind to an empty list...but however you populate your list, this just shows how the Browsable attribute could be used. *编辑:显然,您不想绑定到空列表...但是,尽管您填充了列表,但这仅显示了如何使用Browsable属性。
First bind the grid and then try this code. 首先绑定网格,然后尝试此代码。
GridViewId.Columns[index].Visible = false;//Put index number to hide the Columns like 0,1 etc..
Reference : More Details 参考: 更多详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.