博客
关于我
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实现password generator复杂密码生成器算法(附完整源码)
    查看>>
    Objective-C实现patience sort耐心排序算法(附完整源码)
    查看>>
    Objective-C实现PCA(附完整源码)
    查看>>
    Objective-C实现perceptron算法(附完整源码)
    查看>>
    Objective-C实现perfect cube完全立方数算法(附完整源码)
    查看>>
    Objective-C实现perfect number完全数算法(附完整源码)
    查看>>
    Objective-C实现perfect square完全平方数算法(附完整源码)
    查看>>
    Objective-C实现permutate Without Repetitions无重复排列算法(附完整源码)
    查看>>
    Objective-C实现pigeon sort鸽巢算法(附完整源码)
    查看>>
    Objective-C实现PNG图片格式转换BMP图片格式(附完整源码)
    查看>>
    Objective-C实现pollard rho大数分解算法(附完整源码)
    查看>>
    Objective-C实现Polynomials多项式算法 (附完整源码)
    查看>>
    Objective-C实现pooling functions池化函数算法(附完整源码)
    查看>>
    Objective-C实现porta密码算法(附完整源码)
    查看>>
    Objective-C实现Pow Logarithmic幂函数与对数函数算法 (附完整源码)
    查看>>
    Objective-C实现power iteration幂迭代算法(附完整源码)
    查看>>
    Objective-C实现powLinear函数和powFaster函数算法 (附完整源码)
    查看>>
    Objective-C实现pow函数功能(附完整源码)
    查看>>
    Objective-C实现prefix conversions string前缀转换字符串算法(附完整源码)
    查看>>
    Objective-C实现prefix conversions前缀转换算法(附完整源码)
    查看>>