博客
关于我
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/

    你可能感兴趣的文章
    ppt上的倒计时小工具_PPT中有哪些「看似很 LOW,实则惊艳」的小工具
    查看>>
    PPT添加视频的路径问题
    查看>>
    PPT美化插件 islide 安装过程问题“加载com加载项时运行出现错误”
    查看>>
    Prefix Tuning:详细解读Optimizing Continuous Prompts for Generation
    查看>>
    PreparedStatement 与Statement 的区别,以及为什么推荐使用 PreparedStatement ?
    查看>>
    PreparedStatement 查询 In 语句 setArray 等介绍。
    查看>>
    presentModalViewController显示半透明的一个view
    查看>>
    PresentViewController切换界面
    查看>>
    PyTorch之torch.utils.data.DataLoader解读
    查看>>
    PyTorch之DataLoader杂谈
    查看>>
    presto、druid、sparkSQL、kylin的对比分析
    查看>>
    Presto分布式大数据查询引擎
    查看>>
    Presto架构及原理
    查看>>
    Presto(一)集群部署
    查看>>
    Presto(二)开启安全认证
    查看>>
    Pricing procedure Steps and Details in SAP MM (from SCN)
    查看>>
    Prim 算法在不同权重范围内的性能分析及其实现
    查看>>
    Primace 5.0软件与KEIL单片机软件联合在线仿真步骤
    查看>>
    Prime Distance
    查看>>
    Prim求MST最小生成树
    查看>>