Browse Source

如果点击的是CheckBoxColumn,则不进行操作

章政 8 years ago
parent
commit
8b752caa04

+ 9 - 5
UAS-MES/CustomControl/DataGrid_View/DataGridViewWithCheckBox.cs

@@ -20,12 +20,16 @@ namespace UAS_MES.CustomControl.DataGrid_View
         {
             if (Columns[0] is DataGridViewCheckBoxColumn && e.ColumnIndex >= 0 && e.RowIndex >= 0)
             {
-                if (Rows[e.RowIndex].Cells[0].Value.ToString() == "0")
+                if (!(Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn))
                 {
-                    Rows[e.RowIndex].Cells[0].Value = 1;
-                }
-                else {
-                    Rows[e.RowIndex].Cells[0].Value = 0;
+                    if (Rows[e.RowIndex].Cells[0].Value.ToString() == "0")
+                    {
+                        Rows[e.RowIndex].Cells[0].Value = 1;
+                    }
+                    else
+                    {
+                        Rows[e.RowIndex].Cells[0].Value = 0;
+                    }
                 }
             }
         }

+ 12 - 2
UAS-MES/CustomControl/DataGrid_View/DataGridViewWithSerialNum.cs

@@ -27,9 +27,19 @@ namespace UAS_MES.CustomControl.DataGrid_View
 
         private void DataGridViewWithSerialNum_CellContentClick(object sender, DataGridViewCellEventArgs e)
         {
-            if (Columns[0] is DataGridViewCheckBoxColumn && e.ColumnIndex > 0)
+            if (Columns[0] is DataGridViewCheckBoxColumn && e.ColumnIndex >= 0 && e.RowIndex >= 0)
             {
-                Rows[e.RowIndex].Cells[0].Value = true;
+                if (!(Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn))
+                {
+                    if (Rows[e.RowIndex].Cells[0].Value.ToString() == "0")
+                    {
+                        Rows[e.RowIndex].Cells[0].Value = 1;
+                    }
+                    else
+                    {
+                        Rows[e.RowIndex].Cells[0].Value = 0;
+                    }
+                }
             }
         }
     }