| | |
Problem with ComboBox DataGridView Column
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Oct 2008
Posts: 21
Reputation:
Solved Threads: 0
Hi everybody,
if you please i have a problem with the display field of a combobox column in datagridview...
here is my code to add the column :
'First filling the datatable
Dim dt As New DataTable
Dim da As New SqlDataAdapter
Dim query As String = "SELECT id, name FROM Company_Tbl ORDER BY id "
con.open()
Dim mycommand As New SqlCommand(query, con.getConn)
da.SelectCommand = mycommand
da.Fill(dt)
con.close()
'Setting the combobox column properites
With comboBoxColumn
.DataSource = dt
.DataPropertyName = "company_name"
.Name = "company_name"
.Width = 100
.HeaderText = "Company"
.DisplayMember = "name"
.ValueMember = "id"
.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
End With
Dim loc As Integer = grdViewVisaDetails.Columns.IndexOf(grdViewVisaDetails.Columns("company_name"))
grdViewVisaDetails.Columns.RemoveAt(loc)
grdViewVisaDetails.Columns.Insert(loc, comboBoxColumn)
'The problem is the value dispalyed on the grdview is the value field (id) not the display field (name) ..
but when am editing(cellcontentclick) the combobox displays the dispaly field and when finish editing it again display the value field
I provided a picture so this will explain what i mean
Thank u all in advance
if you please i have a problem with the display field of a combobox column in datagridview...
here is my code to add the column :
'First filling the datatable
Dim dt As New DataTable
Dim da As New SqlDataAdapter
Dim query As String = "SELECT id, name FROM Company_Tbl ORDER BY id "
con.open()
Dim mycommand As New SqlCommand(query, con.getConn)
da.SelectCommand = mycommand
da.Fill(dt)
con.close()
'Setting the combobox column properites
With comboBoxColumn
.DataSource = dt
.DataPropertyName = "company_name"
.Name = "company_name"
.Width = 100
.HeaderText = "Company"
.DisplayMember = "name"
.ValueMember = "id"
.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton
End With
Dim loc As Integer = grdViewVisaDetails.Columns.IndexOf(grdViewVisaDetails.Columns("company_name"))
grdViewVisaDetails.Columns.RemoveAt(loc)
grdViewVisaDetails.Columns.Insert(loc, comboBoxColumn)
'The problem is the value dispalyed on the grdview is the value field (id) not the display field (name) ..
but when am editing(cellcontentclick) the combobox displays the dispaly field and when finish editing it again display the value field
I provided a picture so this will explain what i mean
Thank u all in advance
![]() |
Similar Threads
Other Threads in the VB.NET Forum
- Previous Thread: vb dot net help
- Next Thread: Transparent Treeview
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2005 2008 access account arithmetic array assignment basic box button buttons center check code component connectionstring convert crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dissertationthesis dosconsolevb.net dropdownlist excel fade file-dialog firewall folder ftp generatetags hardcopy image images input insert intel isnumericfuntioncall math monitor navigate net networking opacity output passingparameters peertopeervideostreaming picturebox picturebox1 port problem problemwithinstallation project record reports" savedialog searchvb.net select serial shutdown string survey tcp temp temperature text textbox timer toolbox trim updown user useraccounts usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf





