Why, add a row in datasource, it adds an extra row in the datagridview
-
Monday, July 11, 2011 3:42 PM
Dear Friends
To add Row programmatically,
Connected Datagridview with datatable
I like to add Blank Row in the datagridview, So
On the Last Cell, CellLeave Event
Datatable1.Rows.Add()
It is adding a row in the dataTable, but adding two rows in the datagridview, why...?
Any body able to help me, out of situtation..?
Thanks in Advance.
All Replies
-
Wednesday, July 13, 2011 1:05 PMModerator
Hi Reddiyar,
Welcome to the MSDN Forum.
I recommand you add one line in the CellLeave event to check whether the event has been fired twice:
Console.WriteLine("CellLeaver event fired");
If you can see two lines in the output window, it means the datatable1 added two rows.
One more test:
you can add a new rows with data rather than blank row to check the datagridview add duplicate rows.
After all, it still doesnot work, please make a simple code snippet which can reproduce your scenario, and post it here, all the intrested community members can check it and find the root cause to help you out.
I look forward you.
Best regards,
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Marked As Answer by Mike FengMicrosoft Contingent Staff, Moderator Wednesday, July 20, 2011 1:52 PM
-
Monday, April 30, 2012 6:28 PM
I have experienced the same. I am a rookie VB programmer (self-taught, relying on surfing for problem resolution).
Dim newRow As myExtrasDataSet4.myFlexPurchasesRow
newRow = MyExtrasDataSet4.myFlexPurchases.NewRow()
newRow.Retailer = RetailerTextBox.Text
Dim newDatestamp As String
Dim newTimeDatestamp As String
newDatestamp = DateTextBox.Text
newRow._Date = newDatestamp
newTimeDatestamp = Format(Now)
newRow.Timestamp = newTimeDatestamp
displayNum2dp = AmountTextBox.Text
display2dp = displayNum2dp.ToString("F")
newRow.Amount = display2dp
newRow.Acknowledged = 0
Try
MyExtrasDataSet4.myFlexPurchases.Rows.Add(newRow)
Catch
' to code
MsgBox("Abend")
Return
End Try
Any advice appreciated. Also, my clumsy approach to formatting to 2 decimal places only works on one of the rows (it only goes thru this code once - evidenced by use of a Msgbox) - so it is adding the row to the table twice but only once by the code logic. Row is still in DGV on re-starting the application
- Edited by Steven J Lewis Monday, April 30, 2012 6:31 PM
- Proposed As Answer by Steven J Lewis Wednesday, May 02, 2012 4:51 PM
- Unproposed As Answer by Steven J Lewis Wednesday, May 02, 2012 4:51 PM
-
Wednesday, May 02, 2012 4:52 PM
my TextBox were dragged to form from the Database Explorer. Once I made them a normal Text box, the button didn't insert the data twice- Proposed As Answer by Steven J Lewis Wednesday, May 02, 2012 4:52 PM

