如何删除datagridview单元格

如何删除datagridview单元格

本文介绍了如何删除datagridview单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的程序隐藏了空白或空数据网格视图单元格。我想找到一种完全删除这些单元格的方法。原因是,在隐藏了空白单元格后,它们会在经过我的其他验证之后重新出现。检查这些验证以查看单元格是否包含任何无效输入,例如负数,非数字输入和空白单元格。如果它们包含上述任何一个,它们将填充默认值,从而使我的隐藏单元格重新出现。希望如果有一种方法可以删除这些单元格,它们将无法更改填充默认数据。我隐藏这些单元格的代码如下。如果有人能弄清楚如何删除这些细胞我会非常感激! :)



Currently I have my program hiding blank or empty datagridview cells. I want to find a way to delete these cells entirely. The reason being, after the blank cells were hidden they would reappear after going through some of my other validations. These validations checked to see if the cells contained any invalid input such as negative numbers,non-numeric input and blank cells. If they contained any of the above they would be populated with default values, thus making my hidden cells reappear. Hopefully if there is a way to delete these cells they won't have a change of getting filled with default data. My code to make these cells hidden is below. If anyone can figure out how to delete these cells I would greatly appreciate it! :)

Private Sub DataGridView1_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles DataGridView1.DataBindingComplete
       For Each Row As DataGridViewRow In CType(sender, DataGridView).Rows
           Dim Visible As Boolean = True

           If Row.Cells(0).Value Is DBNull.Value Then
               Visible = False
           End If
           Row.Visible = Visible
       Next

   End Sub

推荐答案

myDataGridView.Rows.RemoveAt(rowToDelete);





Please请参阅: []。



-SA



这篇关于如何删除datagridview单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:14