dev GridControl双击行事件

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

       //双击行弹出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-05-12 22:32  梦想(胡大利)  阅读(1019)  评论(1编辑  收藏  举报