Windows Develop Bookmark and Share   
 index > Windows Forms General > When adding new row in Data gridView Preivous Row data got cleared? Why?
 

When adding new row in Data gridView Preivous Row data got cleared? Why?

Hi Experts.
I'm using Data GridView in VB.net. I add the rows dynamically by using Rows.Add() .
and after adding the row i set the value of last row in the gridView. this works fine for first time but when i add the second row , data from the first row got deleted. How this possible?
At which index Rows.Add() will add the row. if it add the row at last then my program should work fine.

Here is the example of my code (please don't look at syntax error as i have not Studio right now)

datagridview.rows.add()
datagridview.rows(datagridview.rowcount-1).cells(0).value = Somevalue

this will update the only last row every time and previously added row's data got cleared.

Please help

Agnihotri123  Sunday, September 27, 2009 7:44 PM
Hi Agnihotri,

I can reproduce the issue on my side. datagridview.rows(datagridview.rowcount-1 ).cells(0).value is the last row (NewRow with star at the row header). You should use
datagridview.rows(datagridview.rowcount-2 ).cells(0).value. That is the actually last row.

Hope you can solve the problem. If you have any question, please feel free to tell me.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Wednesday, September 30, 2009 7:22 AM
That is because Row Addition Operation wasnt completed for row at the index RowCount-1

use

DataGridView1.Rows.Add((i + 1).ToString, Nothing,...nothing for all columns) instead of setting single Cell.


Thanks

â™?My Blog â™?My Flickr â™?My Facebook â™?YOUR Place to have fun time !
Omie  Sunday, September 27, 2009 8:14 PM
Hi Agnihotri,

I can reproduce the issue on my side. datagridview.rows(datagridview.rowcount-1 ).cells(0).value is the last row (NewRow with star at the row header). You should use
datagridview.rows(datagridview.rowcount-2 ).cells(0).value. That is the actually last row.

Hope you can solve the problem. If you have any question, please feel free to tell me.

Sincerely,
Kira Qian
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework!
Kira Qian  Wednesday, September 30, 2009 7:22 AM

You can use google to search for other answers

Custom Search

More Threads

• Axshdocvw.Axwebbrowser displaying SQL Server Reporting Services reports
• ListBox textcolor on selected item
• how to use datagridview to extract values from a function?Urgent matter
• What permission is required for Process.Start()?
• WebBrowser_NewWindow help --->
• NumericUpDown Control binding issues
• Resetting DOCK property messes things up
• Create Trace in my application
• Page setup
• Need Advice On WinForm Architecture