DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Problem with ComboBox DataGridView Column (http://www.daniweb.com/forums/thread164722.html)

Eyo Dec 29th, 2008 6:40 am
Problem with ComboBox DataGridView Column
 
1 Attachment(s)
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


All times are GMT -4. The time now is 9:58 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC