如何刷新Combobox项目 [英] How to refresh Combobox items

查看:76
本文介绍了如何刷新Combobox项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows窗体上有几个字段,它们带有组合框。我使用数据处理这些组合框。代码如下所示。一切正常,但有一个问题。



Have several fields on windows form which inplement with comboboxes. I porpulate these comboboxes with datatble. The code is shown below. Everything works fine but there is one problem.

Public Sub getFamilyRel(cb As ComboBox)
        Try
            Dim CMD As New SqlClient.SqlCommand
            Dim dt As New DataTable
            CMD.CommandText = "select Code, code + ' - ' + description as Des from famrelup"
            CMD.CommandType = CommandType.Text
            Dim CN As New SqlClient.SqlConnection(My.Settings.cdataConnectionString.ToUpper)
            CMD.Connection = CN
            CN.Open()
            Dim RDR As New SqlClient.SqlDataAdapter
            RDR.SelectCommand = CMD
            RDR.Fill(dt)
            With cb
                .DataSource = dt
                .ValueMember = "code"
                .DisplayMember = "des"
            End With
        Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub





问题是我更新了通过模态表单填充组合框的基表,除非我重新加载,否则这些更新不会显示在组合框中包含组合框的表单。



我想知道是否有人可以帮助我将更新显示在组合框列表中而无需重新加载表单。



我正在使用.NET 2012



感谢您的常规帮助



The problem is that I update the base tables that populate the comboboxes via modal forms and these updates do not show up in the comboboxes unless I reload the form which contains the comboboxes.

I wonder if anybody can help me to have the updates show up in the comboboxes lists without reloading the form.

I am using .NET 2012

Thanks for usual assistance

推荐答案

这篇关于如何刷新Combobox项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆