Question

Combobox is populated from datagridview (first column - Company ticker symbols). Datagridview show only those rows that have letter "B" in last column (indicates that item/company shares are bought or sold), so combobox is populated from bought but not sold items.

After item is sold, combobox is not updated, even when I start the app again.

Eg. there are 2 rows, after database update there is only one item left in datagridview, combobox is still showing 2 items. I've tried two different codes for that but didn't have any success.

Dim COUNN As Integer = DataGridView1.RowCount - 1
    ComboBox1.Items.Add(DataGridView1.Rows(COUNN).Cells(1).Value)

and

            For i As Integer = 0 To DataGridView1.Rows.Count - 2
    ComboBox1.Items.Add(DataGridView1.Rows(i).Cells(1).Value)
         NEXT
Était-ce utile?

La solution

Just clear the combo box list of items and then repopulate it after the datgridview gets updated. like this:

ComboBox1.Items.clear()

For i As Integer = 0 To DataGridView1.Rows.Count - 1
    ComboBox1.Items.Add(DataGridView1.Rows(i).Cells(1).Value)
NEXT
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top