mike55 Posted December 3, 2008 Posted December 3, 2008 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. Quote 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)
Nate Bross Posted December 3, 2008 Posted December 3, 2008 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. Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
mike55 Posted December 4, 2008 Author Posted December 4, 2008 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. Quote 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)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.