簡體   English   中英

在datagridview更新后重新填充組合框

[英]Repopulate Combobox after datagridview update

組合框是從datagridview填充的(第一列-公司代碼)。 Datagridview僅顯示最后一列中帶有字母“ B”的行(指示已購買或出售項目/公司股份),因此,組合框由已購買但未出售的項目填充。

項目出售后,即使我再次啟動應用程序,組合框也不會更新。

例如。 有2行,數據庫更新后,datagridview中僅剩一項,組合框仍顯示2項。 我為此嘗試了兩種不同的代碼,但沒有成功。

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

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

只需清除項目的組合框列表,然后在datgridview更新后重新填充即可。 像這樣:

ComboBox1.Items.clear()

For i As Integer = 0 To DataGridView1.Rows.Count - 1
    ComboBox1.Items.Add(DataGridView1.Rows(i).Cells(1).Value)
NEXT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM