簡體   English   中英

隱藏datagridview中的id列,但需要使用它

[英]Hide id column from datagridview but need to use it

我想從datagridview隱藏id列。 我嘗試通過更改存儲過程/ SQL查詢來解決問題,但是它由於某些原因而無法獲取該條目的ID,我也需要每個條目的ID但又不想在前端顯示。

有什么建議嗎?

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);
}

如評論所述,您可以執行以下操作:

dgName.Columns[i].Visible = false;

或者,如果要綁定到類,則可以在數據值上設置自定義屬性,如下所示:

public class Row {
   [Browsable(false)]
   public int Id {get;set;}
   public string Name {get;set;}
}
//dgName.DataSource = new BindingList<Row>();

*編輯:顯然,您不想綁定到空列表...但是,盡管您填充了列表,但這僅顯示了如何使用Browsable屬性。

首先綁定網格,然后嘗試此代碼。

GridViewId.Columns[index].Visible = false;//Put index number to hide the Columns like 0,1 etc..

參考: 更多詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM