zoukankan      html  css  js  c++  java
  • DevExpress gridview 添加全选

    1、通过check多选框选择

    给当前数据源添加一条,列名Check 然后在gridview添加一列绑定Check列名

    dtOrderBind.Columns.Add("Check", System.Type.GetType("System.Boolean"));

    指定全选列(Check)的imageIndex默认图片(用微软Imagelist控件)

    以下是gridview点击事件

    View Code
     #region 事件:订单全选
    private void grvPrintOrder_Click(object sender, EventArgs e)
    {
    Point point = this.grPrintOrder.PointToClient(Cursor.Position);
    DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hitInfo = this.grvPrintOrder.CalcHitInfo(point);
    if (hitInfo.InColumnPanel == true)
    {
    string s = hitInfo.Column.FieldName;
    //判断当前当击列是否是全选列
    if (s == "Check")
    {
    if (Convert.ToBoolean(hitInfo.Column.Tag) == false)
    {
    hitInfo.Column.Tag = true;
    hitInfo.Column.ImageIndex = 1;
    ChangeChk = true;
    ChkSelect();
    }
    else
    {
    hitInfo.Column.Tag = false;
    hitInfo.Column.ImageIndex = 0;
    ChangeChk = false;
    ChkSelect();
    }
    }
    }
    }
    #endregion

    得到当前选中先

    View Code
    this.grPrintOrder.FocusedView.CloseEditor();
    this.grPrintOrder.FocusedView.UpdateCurrentRow();
    string value = "";
    for (int i = 0; i < this.grvPrintOrder.RowCount; i++)
    {
    value = this.grvPrintOrder.GetDataRow(i)["Check"].ToString();
    if (value.ToLower() == "true")
    {
    if (!list.Contains(this.grvPrintOrder.GetRowCellValue(i, "id").ToString()))
    {
    list.Add(this.grvPrintOrder.GetRowCellValue(i, "id").ToString());
    }
    }
    }

    this.grPrintOrder.FocusedView.CloseEditor();

    this.grPrintOrder.FocusedView.UpdateCurrentRow();

    这二行代码一定要加上,不然得不到最后一个选择。

    2、通过按住shift或ctrl多选

    首先设置将gridview设置为多选

      // 设置为多选

    this.grvPrintOrder.OptionsSelection.MultiSelect = true;

    this.grvPrintOrder.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;

    得到当前用户选择的行

    View Code
      int[] grvarry= this.gridView1.GetSelectedRows();     
    for (int i = 0; i < grvarry.Length;i++ )
    {
    DataRow row = this.gridView1.GetDataRow(grvarry[i]);
    if(row!=null)
    {
    XtraMessageBox.Show(row["comid"].ToString());
    }
    }
    this.gridView1.MoveNext();



      



  • 相关阅读:
    Unix / 类 Unix shell 中有哪些很酷很冷门很少用很有用的命令?(转)
    5分钟用Spring4 搭建一个REST WebService(转)
    一本好看的书————《反欺骗的艺术——世界传奇黑客的经历分享》
    国内外从事CV相关的企业
    定积分解法
    c++中&amp;和&amp;&amp;有什么差别
    树莓派相关-树莓派串口配置方法
    Linux下df与du两个命令的差别?
    veridata实验举例(2)验证表BONUS与表SALGRADE两节点同步情况
    Java替代C语言的可能性
  • 原文地址:https://www.cnblogs.com/freexiaoyu/p/2219817.html
Copyright © 2011-2022 走看看