Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

'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.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted
Try trimming down your SELECT statement to only include those values that you want. you can also remove the "auto-generate columns" property; this will require you to manually add each column that you DO want, and all others will be ignored.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
Need the extra columns as they contain timestamp and audit details. One of the columns that I bring back is binded to DataGridViewComboBoxColumn that contains three values. When the value is changed, I need to timestamp it and record what user made the changes. The user can then hit a save button that transports the updated dataset to the backend and calls the dataadapter.update method thus updating the database.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...