• WinForm messageboxbuttons 和 三级联动


     MessageBoxButtons:

    常用:点击取消不执行任何操作,点击确定,执行lable中的语句(是否删除时,常用)

    点击按钮中的代码:

    DialogResult dr= MessageBox.Show("是否继续?", "警告!!!", MessageBoxButtons.OKCancel);
    if(dr==DialogResult.OK)
    {
    label1.Text = "今天天气不错!";
    }

    效果图:

    三级联动:

    三个ComboBox,经典:省-市-区/县

    public class ChinaStates  //实体类
    {
    public string AreaCode { get; set; }
    public string AreaName { get; set; }
    public string ParentAreaCode { get; set; }

    }

    public class ChinaStatesData  //数据访问类
    {
    SqlConnection conn = null;
    SqlCommand cmd = null;

    public ChinaData()
    {
    conn = new SqlConnection("server=.;database=mydb;user=sa;pwd=123;");
    cmd = conn.CreateCommand();
    }

    public List<ChinaStates> Select(string pcode)
    {
    List<ChinaStates> list = new List<ChinaStates>();
    cmd.CommandText = "select *from ChinaStates where ParentAreaCode = @a";
    cmd.Parameters.Clear();
    cmd.Parameters.Add("@a", pcode);
    conn.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    while (dr.Read())
    {
    ChinaStates c = new ChinaStates()
    {
    AreaCode = dr[0].ToString(),
    AreaName = dr[1].ToString(),
    ParentAreaCode = dr[2].ToString()
    };
    list.Add(c);
    }
    }
    conn.Close();
    return list;
    }}

    主函数中调用:

    AreaDataBind(comboBox1, "0001");
    AreaDataBind(comboBox2, comboBox1.SelectedValue.ToString());
    AreaDataBind(comboBox3, comboBox2.SelectedValue.ToString());

    方法:

    public void AreaDataBind(ComboBox cb, string Pcode)
    {
    cb.DataSource = new ChinaData().Select(Pcode);  //连接数据源
    cb.DisplayMember = "AreaName";  //显示
    cb.ValueMember = "AreaCode";  //隐藏
    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)  //点击省时,市也跟随变化
    {
      AreaDataBind(comboBox2, comboBox1.SelectedValue.ToString());
    }

    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)  //点击市时,区县跟随变化
    {
      AreaDataBind(comboBox3, comboBox2.SelectedValue.ToString());
    }

  • 相关阅读:
    基于微软解决方案的负载测试实现知识库1____(转)理解.NET中的数据库连接池
    [转] Performance vs. load vs. stress testing _Grig Gheorghiu (翻译水平有限,如有错误请帮忙刊正)
    Bill Gates Centimillionaire and one poor man.
    VB Comwrapper 的实现
    使用接口作为返回值
    如何排查SQL死锁的错误?
    VC++动态链接库编程之DLL典型实例
    VC++动态链接库编程之DLL木马
    VC中获取窗口句柄的各种方法 .
    VC++动态链接库编程之MFC扩展 DLL
  • 原文地址:https://www.cnblogs.com/hcx999/p/5910953.html
Copyright © 2020-2023  润新知