Browse Source

增加 GridView.GridHitInfo 演示

ifu25 6 years ago
parent
commit
2dba3df0f3

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+bin
+obj
+.vs
+.svn

+ 8 - 0
WinFormDemo/GridViewDoubleClickArgs.cs

@@ -0,0 +1,8 @@
+namespace WinFormDemo
+{
+    internal class GridViewDoubleClickArgs
+    {
+        public string ColumnName { get; set; }
+        public int RowIndex { get; set; }
+    }
+}

+ 32 - 0
WinFormDemo/GridViewGridHitInfo.cs

@@ -0,0 +1,32 @@
+using System.Windows.Forms;
+using DevExpress.XtraGrid.Views.Grid;
+using DevExpress.XtraGrid.Views.Grid.ViewInfo;
+
+namespace WinFormDemo
+{
+    class GridViewGridHitInfo
+    {
+        public void demo()
+        {
+            GridView gv = new GridView();
+
+            /**
+             * GridView 鼠标双击获取双击到的单元格信息
+             * */
+
+            gv.MouseDown += (s, e) =>
+            {
+                if (e.Button != MouseButtons.Left || e.Clicks != 2) return; //不是双击
+
+                if (gv.State == GridState.ColumnDown) return; //是否列标题
+
+                GridHitInfo info = gv.CalcHitInfo(e.X, e.Y);
+                if (info.HitTest == GridHitTest.RowCell) //双击单元格
+                {
+                    string columnName = info.Column.FieldName; //点击的列
+                    int rowIndex = info.RowHandle; //点击的行
+                }
+            };
+        }
+    }
+}

+ 2 - 3
WinFormDemo/WinFormDemo.csproj

@@ -61,6 +61,8 @@
       <DependentUpon>FormMain.cs</DependentUpon>
     </Compile>
     <Compile Include="GridViewBeginUpdate.cs" />
+    <Compile Include="GridViewDoubleClickArgs.cs" />
+    <Compile Include="GridViewGridHitInfo.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
@@ -82,9 +84,6 @@
       <DesignTimeSharedInput>True</DesignTimeSharedInput>
     </Compile>
   </ItemGroup>
-  <ItemGroup>
-    <None Include="App.config" />
-  </ItemGroup>
   <ItemGroup>
     <Content Include="Libs\DevExpress.XtraGrid.v15.1.dll" />
     <Content Include="Libs\PEMSoft.Client.SYS.WnAppHost.exe" />