使用组合框刷新另一个组合框 [英] Using a ComboBox to Refresh another Combo Box

查看:132
本文介绍了使用组合框刷新另一个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

很抱歉问一个愚蠢/愚蠢的问题...

我是这一切的新手,并且正在使用Visual Studio 2010学习VB .NET ...

我只是有一个问题,因为我似乎无法在Internet上的任何地方找到答案...同样,我们还没有达到课堂上的这一部分..

假设我有2个组合框... cmb1和cmb2 ..都是访问表中的数据集..

如何使cmb2根据cmb1的值刷新?

例如;如果说cmb1,周期1,那么我希望cmb2仅基于周期1中的项目显示结果?

任何帮助将不胜感激

Ross the newb

Hi there,

Sorry to ask a silly/stupid question...

I''m new to all this and i''m in the process of learning VB .NET using Visual Studio 2010...

I just had a question because I cannot seem to find the answers anywhere on the internet... also we are not upto this part in class yet..

Say I have 2 combo boxs... cmb1 and cmb2.. both are datasets from an access table..

how do I make it so cmb2 refreshes based on the value of cmb1?

eg; if cmb1 is say, period 1, then i want cmb2 to only show results bases on items I have in period 1?

Any help would be greatly appreciated

Ross the newb

推荐答案

您似乎想要的称为级联下拉列表.搜索该词,您将找到大量信息.它比这里有足够的空间来描述要复杂得多.
What you seem to want is called a cascading drop down. Search for that term and you will find plenty of info. Its more complicated than there is space here to describe adequately


我写了以下子例程,它可以帮助您根据在第一个Combobox上选择的值刷新第二个ComboBox.
只需在您的应用程序中复制此代码,然后在ComboBox1_SelectedIndexChnged上调用此方法即可.
I wrote the following subrutin which will help you to refresh Second ComboBox based on the value selected on the first Combobox.
Just Copy this code in your application and call this method on ComboBox1_SelectedIndexChnged.
Public Sub FillCombo(ByVal idfiles As String, ByVal table As String, ByVal Combo1 As ComboBox, ByVal Combo2 as ComboBox)
        objda.SelectCommand.CommandText = "Select " & idfiles & " FROM " & table & " Where FieldName=" & Combo1 & ""
        Try 
            dr = objda.SelectCommand.ExecuteReader   'Exectuing query
        Catch ex As OleDb.OleDbException
            MessageBox.Show(ex.ToString)       'Providing Error Message
            ErrorLog(ex.ToString)              'Creating ErrorLog
        End Try
        While dr.Read                          'Reading DataReader Items
            Combo2.Items.Add(dr.Item(0))     'Adding Items Into ComboBox
        End While
        dr.Close()                         'Closing DataReader Object
    End Sub


调用上述方法的示例


Example for calling above method

FillCombo("FieldName", "DatabaseTableName", ComboBox1,ComboBox2)


这篇关于使用组合框刷新另一个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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