dev GridControl双击行事件

今天用到了gridcontrol这个控件,要求写一个gridview的双击事件,因为想要的效果是只双击行才出Message,用gridview的Double_Click我没实现,后来想到MouseDown,一试,很简单,首先,仍旧需要将gridview1.OptionsBehavior.Editable设为false,下面是代码:  

  Skelta BPM.NET(全球第一.NET工作流引擎)   Visual WebGui (完美的用户界面解决方案)

  List & Label(图表报表生成控件)   DXperience Uni Premium 白金版(慧都独家)

       //双击行弹出nodeDetail信息

        private void gridView1_MouseDown(object sender, MouseEventArgs e)

        {

            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hInfo = gridView1.CalcHitInfo(new Point(e.X,e.Y));

//判断是否左键双击

            if (e.Button == MouseButtons.Left && e.Clicks == 2)

            {

                //判断光标是否在行范围内

                if (hInfo.InRow)

                {

                    //取得选定行信息

                    string nodeName = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "nodeName").ToString();

                    //string nodeName = gridView1.GetRowCellValue(gridView1.GetSelectedRows()[0], "nodeName").ToString();

                    string sql = "select nodeDetail from treelist where nodeName = '" + nodeName + "'";

                    SqlCommand comm = new SqlCommand(sql, conn);

                    try

                    {

                        conn.Open();

                        MessageBox.Show(comm.ExecuteScalar().ToString(), "Detail");

                    }

                    catch (Exception ex)

                    {

                        MessageBox.Show(ex.Message, "Error");

                    }

                    finally

                    {

                        conn.Close();

                    }

                }

            }

        }

上一篇:XAMl*元素


下一篇:前端基础——js数据类型及判断方法