开发者

how to refresh combobox items in vb .net

h开发者_开发问答ow to refresh combobox items in vb .net


If you're talking about a comboBox on a WinForm that's been assigned to a list of objects using the datasource property, I found that you must nullify the datasource setting and re-assign it every time your list changes.

i.e.

  attendanceDataFiles.DataSource = Nothing
  attendanceDataFiles.DataSource = myFileList.files
  attendanceDataFiles.DisplayMember = "displayName"
  attendanceDataFiles.ValueMember = "fileName"


This is another way to refresh combo box items if your combo box's content is from MySql Database. You can customize your results in the query.

        comboboxname.Items.clear() 'empty combo box content first

        query = "select code, description from tbl_mode_of_payment where cat = 'LICENSE'" 'mysql query that retrieves payment code and its description based on category
        cmd = New MySqlCommand(query, con)
        reader = cmd.ExecuteReader()

        While reader.Read
            comboboxname.Items.Add(reader.GetString("code") + " - " + reader.GetString("description"))  'add results into the combo box
        End While
        con.Close()


Textbox1.Item.Clear() then call.item_tb()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜