| | |
Problem with ComboBox DataGridView Column
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
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 |
.net .net2008 2008 access account add advanced application array basic beginner browser button buttons click code combo cpu cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic employees excel exists fade filter forms generatetags html images input intel internet listview mobile module monitor mysql net number objects open panel pdf picturebox picturebox2 port position print printing printpreview problem regex reuse right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver storedprocedure survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet vista visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year





