WinForm MessageBoxButtons and Level three linkage

Source: Internet
Author: User

MessageBoxButtons:

Commonly used: Click Cancel do not do anything, click OK, execute lable in the statement (if deleted, commonly used)

Click the code in the button:

DialogResult dr= MessageBox.Show ("Do you want to continue? "," Warning!!! ", Messageboxbuttons.okcancel);
if (Dr==dialogresult.ok)
{
Label1. Text = "Nice weather today!" ";
}

Three-level linkage:

Three ComboBox, classic: Province-city-district/County

public class Chinastates//entity class
{
public string AreaCode {get; set;}
public string AreaName {get; set;}
public string Parentareacode {get; set;}

}

public class Chinastatesdata//Data access class
{
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;
}}

Called in the main function:

Areadatabind (ComboBox1, "0001");
Areadatabind (ComboBox2, comboBox1.SelectedValue.ToString ());
Areadatabind (ComboBox3, comboBox2.SelectedValue.ToString ());

Method:

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 ());
}

WinForm MessageBoxButtons and Level three linkage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.