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