I am binding a dataset to a datagridview. My dataset returns about 7 different columns, of which I only want 3 to be visible. To enable me to hide the additional columns, I have added the following code:
I then have a refresh button that allows me to retrieve a new version of the data and automatically binds the data to the datagridview control. The problem is that some of the columns that I have specified as Visible=false are showing up.
Any suggestions on how I can check if the column already exists or simply delete the column in question?
Mike55.
Code:
'Organisation Name
dCol.HeaderText = "Organisation Name"
dCol.Name = "OrganisationName"
dCol.DataPropertyName = "OrganisationName"
dCol.ReadOnly = True
dgvResults.Columns.Add(dCol)
'License Code
dCol = New DataGridViewTextBoxColumn
dCol.HeaderText = "License Code"
dCol.Name = "LicenseCode"
dCol.DataPropertyName = "LicenseCode"
dCol.ReadOnly = True
dgvResults.Columns.Add(dCol)
'Total Waste/Emissions
dCol = New DataGridViewTextBoxColumn
dCol.HeaderText = "Total Waste/Emissions"
dCol.Name = "Total"
dCol.DataPropertyName = "Total"
dCol.ReadOnly = True
dCol.Visible = false
dgvResults.Columns.Add(dCol)
I then have a refresh button that allows me to retrieve a new version of the data and automatically binds the data to the datagridview control. The problem is that some of the columns that I have specified as Visible=false are showing up.
Any suggestions on how I can check if the column already exists or simply delete the column in question?
Mike55.