Avatar of Victor  Charles
Victor Charles
Flag 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
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Victor Charles

8/22/2022 - Mon
Pawan Kumar

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"
Victor Charles

ASKER
Hi,

Which method of thr Grid do I include the code?

Thanks,

Victor
Pawan Kumar

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
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
Pawan Kumar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Pawan Kumar

Hi, Do you need more info on this?
Victor Charles

ASKER
Hi

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

Thanks,

Victor
Pawan Kumar

Here is a sample VB.Net project for you!



Enjoy !
Demo.zip
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Victor Charles

ASKER
Thank you.