Search code examples
c#.netdatagridviewlistboxdatagridviewcolumn

Using List boxes to delete columns in datagridview


I have two list boxes, a datagridview and an Add and Remove button. Listbox1 contains the headers for the columns of the datagridview. Listbox2 contains the list of columns(with headers) currently displayed on the datagridview.

What I can't figure out to do is: when you select a header from the first listbox and hit the Add button how can I get a column with that header to appear on the datagridview?

Do I need to bind the string values of the column headers to a column and then have them add and delete when the correct button is pressed? confused


Solution

  • use this to show and hide column

    Hide

    dataGridView.Columns["ColumnName"].Visible = false

    Show

    dataGridView.Columns["ColumnName"].Visible = true