如何使用组合框选择中的项目填充两个列表框 [英] how to populate two list boxes with items on combo box selection

查看:88
本文介绍了如何使用组合框选择中的项目填充两个列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3张桌子



代理商(经纪人,姓名,地点,日期,年份)

买家(身份证,姓名)

item(brokerid-forign key,name,place,date,year,lotno,lname,description,amt)



现在我已插入记录从表格结束到项目表。



现在我已经采用了另一种形式的2个盒子和1个组合框,



i想要根据组合框选择添加所有lotno及其各自的amt。



例子。 1个单独的代理ID有很多lotno和他们的amt。



所以在组合框选择agentid时,相应的所有批次no和amt将填充在2个单独的列表框中。



任何人都可以帮我PLZ。



i我是新手。



提前感谢。

I have 3tables

agent(brokerid,name,place,date,year)
buyer(id,name)
item(brokerid-forign key,name,place,date,year,lotno,lname,description,amt)

now i have inserted records into item table from form end.

now i have taken 2list box and 1 combobox in another form,

i want to add all the lotno and their respective amt based on combobox selection.

example. 1 single agent id has many lotno and their amt .

so upon combo box selection of agentid,the respective all the lot no and amt will be populated in 2 separate listbox.

can anyone help me plz.

i am new to this.

thanks in advance.

推荐答案

见下面更新代码:



See Below Updated Code :

Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=stamp;user=sa;password=gariahat")
        Dim cmd As New SqlCommand
        Dim ds As New DataSet
        Dim dt As DataTable

        cmd.Connection = cn
        cn.Open()

        Dim da As New SqlDataAdapter("select * from item where broker_id = " + ComboBox1.SelectedValue, cn)
        dt = New DataTable

        ds = New DataSet
        da.Fill(ds, "item")

        For Each row As var In ds.Tables("item").Rows
            ListBox1.Items.Add(DirectCast(row, System.Data.DataRow)("lot_no").ToString())
            ListBox2.Items.Add(DirectCast(row, System.Data.DataRow)("amt").ToString())
        Next


Dim cn As New SqlConnection("Data Source=.\INSTANCE;initial catalog=stamp;user=sa;password=gariahat")
        Dim cmd As New SqlCommand
        Dim ds As New DataSet
        Dim dt As DataTable

        cmd.Connection = cn
        cn.Open()

        Dim da As New SqlDataAdapter("select * from item where broker_id = " + ComboBox1.SelectedItem, cn)
        dt = New DataTable

        ds = New DataSet
        da.Fill(ds, "item")

        Dim sumAmount As Double = 0

        For Each row As DataRow In ds.Tables("item").Rows
            TextBox1.Text = DirectCast(row, System.Data.DataRow)("name").ToString()
            TextBox2.Text = DirectCast(row, System.Data.DataRow)("place").ToString()
            TextBox3.Text = DirectCast(row, System.Data.DataRow)("date").ToString()
            TextBox4.Text = DirectCast(row, System.Data.DataRow)("year").ToString()
            ListBox1.Items.Add(DirectCast(row, System.Data.DataRow)("lot_no").ToString())
            ListBox2.Items.Add(DirectCast(row, System.Data.DataRow)("amt").ToString())

            sumAmount = sumAmount + Convert.ToDouble(DirectCast(row, System.Data.DataRow)("amt"))

        Next

        TextBox6.Text = sumAmount.ToString()
        TextBox7.Text = (0.175 * sumAmount).ToString()

        cn.Close()


In < b>选择索引已更改事件,获取组合框的选定值(brokerid)。



1。现在有一个选择查询批号:

从项目中选择lotno,其中brokerid = [SelectedValue]



将所有lotnos绑定在一个列表框中。



2。 金额的另一个选择查询:

从项目中选择amt,其中brokerid = [SelectedValue]



绑定所有金额在另一个列表框中。
In selected index changed event, get the selected value (brokerid) of the combobox.

1. now one select query for the lot no :
"select lotno from item where brokerid = [SelectedValue]"

Bind all the lotnos in one list box.

2. another select query for the amount :
"select amt from item where brokerid = [SelectedValue]"

Bind all the amounts in another list box.


这篇关于如何使用组合框选择中的项目填充两个列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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