One. TreeView
SelectedNode The selected node
Depth of level node (starting from 0)
Occurs when the AfterSelect node is selected
1. Get the node depth
This.tvlist.SelectNode.Level
2. Get the node name
This.tvlist.SelectNode.Text
Two. Filtering and sorting Data using DataView
RowFilter Specifying filter criteria
Sort specifies how the order is sorted
All is selected by default when the form is run
if (This.tvstulist.SelectedNode.Level = = 0) {
Showstudent ();
}
else if (This.tvstulist.SelectedNode.Level = = 1) {
DataView dv = new DataView (ds. tables["Student"]);
Dv. RowFilter = "Gradename=" "+this.tvstulist.selectednode.text+" ";
This.dgvstulist.DataSource = DV;
}
else if (This.tvstulist.SelectedNode.Level = = 2) {
DataView dv = new DataView (ds. tables["Student"]);
Dv. RowFilter = "Gradename=" + This.tvstulist.SelectedNode.Parent.Text + "' and sex= '" + This.tvstulist.SelectedNode.Text + " ‘";
Dv. Sort = "Studentno desc";
THIS.DGVSTULIST.DATASOURCE=DV;
}
Three. Delete data
SelectionMode Specifies the selected Datagradeview selection method
DialogResult result= MessageBox.Show ("Whether delete", "hint", messageboxbuttons.yesno,messageboxicon.information);
if (result = = Dialogresult.yes) {
Gets the value of the selected study number
int studentno= (int) this.dgvstulist.selectedrows[0]. cells["Studentno"]. Value;
Try
{
Helper. OpenConnection ();
String sql = "Delete from Student where studentno= '" "+studentno+" ";
SqlCommand cmd = new SqlCommand (sql,helper. Con);
int Count=cmd. ExecuteNonQuery ();
if (Count > 0)
{
MessageBox.Show ("Delete succeeded! "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);
Showstudent ();
}
else {
MessageBox.Show ("Delete failed! "," hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception x)
{
MessageBox.Show (X.message);
}
}
Parsing of data filtering and sorting------