3

I want to hide id column from datagridview. 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.

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);
}
2
  • 2
    don't change the stored procedure.. just set the visible property on the ID column in the datagridview = false you need to set the property in your DataGridView design this is not that difficult.. if you are not sure there are lots of examples plus documentation on DataGridView column hiding on the internet..
    – MethodMan
    Feb 29, 2016 at 19:35
  • 1
    thanks bro i searched but there was long detail no body telling simple way as you just guide me thanks a lot highly appreciate. so that is solution for simple binding if use 'datagridview datasource = datatable' than how it can be done Feb 29, 2016 at 19:40

2 Answers 2

4

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.