Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with assigning value of previous row to new row added in DataGridView

Hi,

When adding data in a new row in my DataGridView, I need to automatically assign the COUNTRY column, country value from the previous row or a value from a textbox. How do I achieve this using VB.NET?  Also , How save the record only if more than one column is populated in new row added?

Thanks,

Victor
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Sample example  !! Enjoy !!

Dim newCustomersRow As DataRow = DataSet1.Tables("Customers").NewRow()

newCustomersRow("CustomerID") = "Pawan1312"
newCustomersRow("COUNTRY") = "United States"

DataSet1.Tables("Customers").Rows.Add(newCustomersRow)

DataSet1.Tables(0)(ds.Tables(0).Rows.Count - 1)("COUNTRY") = "United States"
Avatar of Victor  Charles

ASKER

Hi,

Which method of thr Grid do I include the code?

Thanks,

Victor
You can internally use datatable.

You must be using the datatable as a source to a GridView.  You have to use button click event

When you add a new row in GridView , add a row in the table just as mentioned above. After that change the previous row's country

after that again assign that datatable to the GridView
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, Do you need more info on this?
Hi

Will test code this morning and get back to you..

Thanks,

Victor
Here is a sample VB.Net project for you!



Enjoy !
Demo.zip
Thank you.