Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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! :)

VB
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
Posted
Updated 14-Aug-13 2:40am
v2

It's
C#
myDataGridView.Rows.RemoveAt(rowToDelete);


Please see: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx[^].

—SA
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900