组合框绑定问题? [英] Combo box binding problem?

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

问题描述

有三个组合框控件并基于第一个组合框值数据绑定到组合框2并基于第二个组合框2值数据绑定到第三个组合框..我的问题是组合记录是否没有组合值框3然而它显示另一条记录的价值,直到匹配才更改



i还不知道这个问题的任何解决方案...

请帮帮我..



我尝试过:



there are three combo box controls and based on first combo box value data bind to combo box 2 and based on second combo box 2 value data bind to third combo box..my question is if the combination record has no value for combo box 3 and yet it is displaying value form another record and not changing until it is matched

i haven't known any solution for this problem...
please help me..

What I have tried:

internal void bindcompname()
        {
            cmd = new SqlCommand("select CompName from company",conn);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr = dt.NewRow();
            comboscname.DisplayMember = "CompName";
            comboscname.DataSource = dt;
            comboscname.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        private void comboscname_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            cmd = new SqlCommand("select model.ModNum from model inner join company on model.CompName=company.CompName where model.CompName=@cname",conn);
            cmd.Parameters.AddWithValue("@cname",comboscname.Text);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr = dt.NewRow();
            combosmnumber.DisplayMember = "ModNum";
            combosmnumber.DataSource = dt;
            combosmnumber.DropDownStyle = ComboBoxStyle.DropDownList;
        }
        private void combosmnumber_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            cmd = new SqlCommand("select mobile.IMEINo from mobile inner join model on model.ModId=mobile.ModId inner join company c on c.CompName=mobile.CompName where model.ModNum=@mid and mobile.Status=@sts", conn);
            cmd.Parameters.AddWithValue("@mid", combosmnumber.Text);
            cmd.Parameters.AddWithValue("@sts", "NotSold");
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr = dt.NewRow();
            combosimeinumber.DisplayMember = "IMEINo";
            combosimeinumber.DataSource = dt;
            combosimeinumber.DropDownStyle = ComboBoxStyle.DropDownList;
        }

推荐答案

检查一下:

使用C#.Net 在Windows窗体(WinForms)应用程序中级联ComboBox [< a href =https://www.aspforums.net/Threads/828656/Cascading-ComboBox-in-Windows-Forms-WinForms-application-using-C-Net/\"target =_ blanktitle =New Window > ^ ]

级联Winforms Windows窗体中的ComboBox C#VB.NET [ ^ ]
Check this:
Cascading ComboBox in Windows Forms (WinForms) application using C# .Net[^]
Cascading ComboBox In Winforms Windows Forms C# VB.NET[^]


Quote:

internal void bindcompname()

{

cmd = new SqlCommand(select compName from company,conn);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();

da.Fill(dt);

DataRow dr = dt.NewRow();

comboscname.DisplayMember =CompName;

comboscname.DataSource = dt;

comboscname.DropDownStyle = ComboBoxStyle.DropDownList;

}

private void comboscname_SelectedIndexChanged_1(object sender,EventArgs e)

{

cmd = new SqlCommand(select model.ModNum from model inner join company on model.CompName = company.CompName where model.CompName=@cname,conn);

cmd.Parameters.AddWithValue (@cname,comboscname.Text);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataTable dt = new DataTable();

da.Fill(dt);

DataRow dr = dt.NewRow();

combosmnumber.DisplayMember =ModNum;

combosmnumber.DataSource = dt;

combosmnumber.DropDownStyle = ComboBoxStyle.DropDownList;

}

private void combosmnumber_SelectedIndexChanged_1(object sender,EventArgs e)

{

cmd = new SqlCommand(从模型上的移动内连接模型中选择mobile.IMEINo。 modId = mobile.ModId内部联接公司c在c.CompName = mobile.CompName,其中model.ModNum =@mid和mobile.Status=@sts,conn);

cmd.Parameters.AddWithValue( @mid,combosmnumber.Text);

cmd.Parameters.AddWithValue(@ sts,NotSold);

SqlDataAdapter da = new SqlDataAdapter(cmd) ;

DataTable dt = new DataTable();

da.Fill(dt);

DataRow dr = dt.NewRow();

combosimeinumber.DisplayMember =IMEINo;

combosimeinumber.DataSource = dt;

combosimeinumber.DropDownStyle = ComboBoxStyle.DropDownList;

}

internal void bindcompname()
{
cmd = new SqlCommand("select CompName from company",conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
comboscname.DisplayMember = "CompName";
comboscname.DataSource = dt;
comboscname.DropDownStyle = ComboBoxStyle.DropDownList;
}
private void comboscname_SelectedIndexChanged_1(object sender, EventArgs e)
{
cmd = new SqlCommand("select model.ModNum from model inner join company on model.CompName=company.CompName where model.CompName=@cname",conn);
cmd.Parameters.AddWithValue("@cname",comboscname.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
combosmnumber.DisplayMember = "ModNum";
combosmnumber.DataSource = dt;
combosmnumber.DropDownStyle = ComboBoxStyle.DropDownList;
}
private void combosmnumber_SelectedIndexChanged_1(object sender, EventArgs e)
{
cmd = new SqlCommand("select mobile.IMEINo from mobile inner join model on model.ModId=mobile.ModId inner join company c on c.CompName=mobile.CompName where model.ModNum=@mid and mobile.Status=@sts", conn);
cmd.Parameters.AddWithValue("@mid", combosmnumber.Text);
cmd.Parameters.AddWithValue("@sts", "NotSold");
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
combosimeinumber.DisplayMember = "IMEINo";
combosimeinumber.DataSource = dt;
combosimeinumber.DropDownStyle = ComboBoxStyle.DropDownList;
}


这篇关于组合框绑定问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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