DEV GridControl双击行事件

首先,需要将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 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();  

                    }  

                }  

            }  

        } 

 

你可能感兴趣的:(grid)