Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Below code cleare value of one cell of datagridview row
Dgv.Rows(Rno).Cells("ColItemCode1").Value = ""

If i want to cleare entire row that is make entire row empty is there any single code other then clearing each cell.

What I have tried:

Dgv.Rows(Rno).Cells("ColItemCode1").Value = ""
Posted
Updated 1-May-20 0:53am
Comments
CHill60 1-May-20 5:33am    
How do you populate your datagridview - do you use data binding?

Also - is this winforms, wpf, what?

As this already has an incorrect solution here are my comments

If your datagridview has not been populated with databinding then you will need to blank out each cell in the row you want to clear. It's not hard though, and you don't need to know how many cells there are e.g.
C#
foreach(DataGridViewCell cell in Dgv.Rows(Rno).Cells)
{
    cell.Value = string.Empty;
}
You might want to experiment with cells of different types (e.g. dates, hyperlinks, checkboxes)

However, if your datagridview is databound then you will need to blank those values in the source - whatever that might be, and rebind the datasource to the datagridview. Without explicit detail on how you are populating the DGV I can't really give you more
 
Share this answer
 
if you need remove specific row you can use this code
Dim dgvDelRow As DataGridViewRow = Dgv.Rows(Rno)
    Dgv.Rows.RemoveAt(dgvDelRow)
    Dgv.Refresh()

if you need add new row you can use this code
Dgv.Rows.Add("", "", "", "")

or
Dgv.Rows.Insert("", "", "", "", "")

I hope it helps you
Greetings
 
Share this answer
 
Comments
CHill60 1-May-20 6:44am    
None of this will blank an existing row which is what the OP asked for

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