博客
关于我
C#开发之——组合框控件数据绑定(15.11)
阅读量:105 次
发布时间:2019-02-26

本文共 2276 字,大约阅读时间需要 7 分钟。

????????

?Windows????????????????DataSource????????DataSet?DataTable??????????????????????????????????

???????????????TextBox?????Label??????ListBox??????ComboBox????????DataGridView?????????????????????????????????????????????????????????????????

??????????????????????????


???????????

2.1 ???????

??????ComboBox??Windows?????????????????????????Windows????????????????????????????

??????????

  • ?????????????????????????????????ComboBox??????
  • ?????????????????????????????????????????
  • ?????????????????????????????????????DataSource???
  • ???????????????
    • ???????????????????????????Text?????
    • ?????????????????????????Value?????
    • ?????????????????????

  • 2.2 ???????

    ??????????????????????????????DataSource?DisplayMember?ValueMember???????????

    ???????

    ComboBox comboBox1 = new ComboBox();  SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM major", conn);  DataSet ds = new DataSet();  sda.Fill(ds);  comboBox1.DataSource = ds.Tables[0];  comboBox1.DisplayMember = "name";  comboBox1.ValueMember = "id";

    ??????

    3.1 ?????????

    3.1.1 ??????

    ????T-SQL??????????

    CREATE TABLE major (      id INT PRIMARY KEY IDENTITY(1,1),      name VARCHAR(20) UNIQUE  );

    3.1.2 ??????????

  • ??????????????????????
  • ???ComboBox?????????????
    • ???????????????????????????????????????
    • ????????????????????
  • ????????????name?????????????id??????????????????

  • 3.2 ?????????????

    3.2.1 ????

    private void ComboBoxForm_Load(object sender, EventArgs e)  {      SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=test;User ID=sa;Password=root");      try      {          conn.Open();          SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM major", conn);          DataSet ds = new DataSet();          sda.Fill(ds);          comboBox1.DataSource = ds.Tables[0];          comboBox1.DisplayMember = "name";          comboBox1.ValueMember = "id";      }      catch (Exception ex)      {          MessageBox.Show("?????" + ex.Message);      }      finally      {          if (conn != null)          {              conn.Close();          }      }  }

    3.2.2 ????????

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  {      if (comboBox1.Tag != null)      {          MessageBox.Show("????????" + comboBox1.Text);      }  }

    3.3 ??

    ???????????????????????????????????????????????

    转载地址:http://atpz.baihongyu.com/

    你可能感兴趣的文章
    objective-c中的内存管理
    查看>>
    Objective-C之成魔之路【7-类、对象和方法】
    查看>>
    Objective-C享元模式(Flyweight)
    查看>>
    Objective-C以递归的方式实现二叉搜索树算法(附完整源码)
    查看>>
    Objective-C内存管理教程和原理剖析(三)
    查看>>
    Objective-C实现 Greedy Best First Search最佳优先搜索算法(附完整源码)
    查看>>
    Objective-C实现 jugglerSequence杂耍者序列算法 (附完整源码)
    查看>>
    Objective-C实现 lattice path格子路径算法(附完整源码)
    查看>>
    Objective-C实现1000 位斐波那契数算法(附完整源码)
    查看>>
    Objective-C实现2 个数字之间的算术几何平均值算法(附完整源码)
    查看>>
    Objective-C实现2d 表面渲染 3d 点算法(附完整源码)
    查看>>
    Objective-C实现2D变换算法(附完整源码)
    查看>>
    Objective-C实现3n+1猜想(附完整源码)
    查看>>
    Objective-C实现3n+1猜想(附完整源码)
    查看>>
    Objective-C实现9x9乘法表算法(附完整源码)
    查看>>
    Objective-C实现9×9二维数组数独算法(附完整源码)
    查看>>
    Objective-C实现A*(A-Star)算法(附完整源码)
    查看>>
    Objective-C实现A-Star算法(附完整源码)
    查看>>
    Objective-C实现abbreviation缩写算法(附完整源码)
    查看>>
    Objective-C实现ABC人工蜂群算法(附完整源码)
    查看>>