• 数据筛选和排序


      一.TreeView
       SelectedNode 选中的节点
       Level 节点的深度(从0开始) 
       AfterSelect 节点选中后发生
       1.获取节点深度
        this.tvlist.SelectNode.Level
       2.获取节点名称
        this.tvlist.SelectNode.Text
      二.使用DataView筛选和排序数据
       RowFilter指定筛选条件
       Sort指定排序方式
       //窗体运行时默认选中全部
                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;
                }
            三.删除数据
             SelectionMode指定选中DataGradeView的选中方式
             DialogResult result= MessageBox.Show("是否删除","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
                if (result == DialogResult.Yes) {
                    //获取选中的学号的值
                    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("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ShowStudent();
                        }
                        else {
                            MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception x)
                    {
                        MessageBox.Show(x.Message);
                    }
                }
  • 相关阅读:
    动态规划总结(01背包 完全背包 多重背包)
    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
    HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)
    HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包)
    HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包)
    HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包)
    HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)
    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
    POJ.3624 Charm Bracelet(DP 01背包)
  • 原文地址:https://www.cnblogs.com/rzbwyj/p/9466127.html
Copyright © 2020-2023  润新知