comboBox控件SelectedIndexChanged时的取值问题

来源:互联网 发布:js 鼠标离开时隐藏 编辑:程序博客网 时间:2024/05/17 01:06

//        comboBox 取值问题
//        A: 在属性 Iitems 添加项
//
//        CobShow.SelectedIndex          选择项的索引
//        CobShow.SelectedItem           选择项的文本
//        CobShow.SelectText             空值
//        CobShow.SelectValue            报错...
//        CobShow.Items[CobShow.SelectedIndex].ToString()  选择项的文本
//
//        B:在程序中添加 CobShow.Item.Add() 结果和上面一样
//
//
//        C:动态绑定数据
//
//        CobShow.SelectedIndex          选择项的索引
//        CobShow.SelectedItem           System.DataRow.DefaultView
//        CobShow.SelectText             空值
//        CobShow.SelectValue            选择项的 VALUE 值
//        CobShow.Text                   选择项的 文本 值
//        CobShow.Items[CobShow.SelectedIndex].ToString()  System.DataRow.DefaultView

经测试我总结出来,结果同上一样:
           VS.NET 2003中语法如下:
           this.comboBox1.DataSource=ExecuteDataSet("select * from socut_data").Tables[0];//ExecuteDataSet返回一个DataSet;
           this.comboBox1.DisplayMember="s_id";
           this.comboBox1.ValueMember="s_id";

          VS.NET 2005中语法如下:
           this.comboBox1.DisplayMember="s_id";
           this.comboBox1.ValueMember="s_id";
           this.comboBox1.DataSource=ExecuteDataSet("select * from socut_data").Tables[0];//ExecuteDataSet返回一个DataSet;

原创粉丝点击