1,105,416 Community Members

Access Vale Selected Row in DataGridview in C#

Member Avatar
abhi10kumar
Junior Poster
185 posts since Feb 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

How to access all values of the selected Row of a DatagridView in C# using Coding, MS Access as a Database..??

Member Avatar
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 557 [?]
Q&As Helped to Solve: 489 [?]
Skill Endorsements: 21 [?]
 
0
 

You would like to get all the values from a dgv`s row?

Lets say you want to get data from 5th row (dgv has 3 columns):

string = column1 = dgv[0,6].Value.ToString();
string = column2 = dgv[1,6].Value.ToString();
string = column3 = dgv[2,6].Value.ToString();

If the column has a default type of string, no need to parse to stirng on the end.
Same goes for columns of type int, boolean, dateTime....
If the column is type of int you simple do:

int column1 = dgv[0,6].Value;//no need to convert

Mitja

Member Avatar
Momerath
Senior Poster
3,831 posts since Aug 2010
Reputation Points: 1,327 [?]
Q&As Helped to Solve: 664 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

There is a typo in your first code block. Don't put '=' between string and the variable names :)

Member Avatar
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 557 [?]
Q&As Helped to Solve: 489 [?]
Skill Endorsements: 21 [?]
 
0
 

ups, sorry, and thx for reminding me. I has to be this way:

string column1 = dgv[0,6].Value.ToString();
string column2 = dgv[1,6].Value.ToString();
string column3 = dgv[2,6].Value.ToString();
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: