惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - niuyy

博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 .net 中用到excel中,检索COM类工厂中的CLSID为{000 24500-0000-0000-C000-000000000046}的组件时失败 客户端获取传递的参数 SQL语句中,插入单引号、添加、删除字段 JS给RadioButtonList赋值 在SQL2000中不显示系统表及系统文件 Embed标签详解 可以拖动,关闭的DIV组合 获取计算机用户名 浏览器字体变小 学习小技巧 ComBox 绑定数据库 C# 读取文本文件 字符编码 在.net中应用事务 数据库索引应用(ms-sql) 开发人员组要注意的网站 C# 在.cs文件中使用正则表达式
ComboBox与其他控件的联动
niuyy · 2007-12-19 · via 博客园 - niuyy

当选择ComboBox的值时其他控件也跟着变化。
窗体控件:comboBox1comboBox2,listBox1textBox1
数据库表字段:ID Name ParentID


 
private void Form1_Load(object sender, EventArgs e)
        
{  DataBindComboBox();
   
        }

  
public void DataBindComboBox()
        
{
            BindingSource bindingSource 
= new BindingSource();
            bindingSource.DataSource 
= myDB.DatabindComboBox(string.Empty).Tables[0];
            comboBox1.DataSource 
= bindingSource;          
            comboBox1.DisplayMember 
= "Name";           
            
        }

事件:

/// <summary>
        
/// 根据选择的省份获取省份的市
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        
{            
            
string Condition = string.Format(" where ParentID in(select ID from DeptTree where Name='{0}')", comboBox1.Text);
             DataTable  dataTable
=myDB.DatabindComboBox(Condition).Tables[0];
             
if (dataTable.Rows.Count > 0)
             
{
                 comboBox2.DataSource 
= dataTable;
                 comboBox2.DisplayMember 
= "Name";
                 listBox1.DataSource 
= dataTable;
                 listBox1.DisplayMember 
= "Name";
                
             }

             
else
             
{
                 comboBox2.DataSource 
= null;
                 listBox1.DataSource 
= null;
             }


           
        }


        
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        
{
            textBox1.Text 
= listBox1.Text.ToString();
        }

   /// <summary>
        
/// 把地名显示到控件中
        
/// </summary>
        
/// <returns></returns>

        public DataSet DatabindComboBox(string Condition)
        
{
            
string sqlstr = "select Name from DeptTree" + Condition;
            
return RunSQL_DataTable(sqlstr);
        }