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

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - 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);
        }