DataGridViewComboBoxColumn Default Value not working

J

John Talli

I have a DataGridView called "ucGrdLCbx_DGV".
I have added a DataGridViewComboBoxColumn to the first column.

Everything works fine except the default value "Local" never
is display at the first selection. The first selection just
stays blank.

I would like the item "Local" to display as the default value
when the grid gets loaded.

What am I doing wrong. THANKS


With Me.ucGrdLCbx_DGV ' ucGrdLCbx_DGV = DataGridView
.Columns.Clear()
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False

' Combobox to first column
Dim ctl As New DataGridViewComboBoxColumn
ctl.Name = "Colmn1"
ctl.HeaderText = "ColmnHdr"
ctl.Width = 75
ctl.Items.Add("None") '
ctl.Items.Add("Local")
ctl.ValueMember = "Local" <<< Default value NEVER shows

' Add the combobox to the DataGridView
.Columns.Add(ctl)

' Bind dataTable to DataGridView
ucGrdLCbx_DGV.DataSource = p_DataTbl

End With


'' ''For Each itm As DataGridViewRow In Me.ucGrdLCbx_DGV.Rows << I also tried
this but it didn't work
'' '' itm.Cells(0).Value = "Local"
'' ''Next


'' ''For Each itm As DataGridViewRow In Me.ucGrdLCbx_DGV.Rows << I also tried
this but it didn't work
'' '' Dim ctl As New DataGridViewComboBoxCell
'' '' ctl = CType(itm.Cells(0), DataGridViewComboBoxCell)
'' '' ctl.ValueMember = "Local"
'' ''Next
 
J

John Talli

Another tidbit for this.

The dataGridView is in a user-control which seems to be a factor.

If from the form (that contains the user-control) in a button:
For Each itm As DataGridViewRow In _ucGrdLCbx.ucGrdLCbx_DGV.Rows
itm.Cells(0).Value = "Local"
Next

where _ucGrdLCbx = user-control and ucGrdLCbx_DGV = dataGridView,
the above code works. (As it always had.)

But the exact same code in the user-control:
For Each itm As DataGridViewRow In ucGrdLCbx_DGV.Rows
itm.Cells(0).Value = "Local"
Next

does not work.

Is there anyway to get it to work from within the user-control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top