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(); 
                    } 
                } 
            } 
        }

 

  

posted @ 2011-09-15 15:11  小锋神  阅读(13016)  评论(0编辑  收藏  举报