954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Access Vale Selected Row in DataGridview in C#

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

abhi10kumar
Junior Poster
126 posts since Feb 2011
Reputation Points: 15
Solved Threads: 1
 

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

Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

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

Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

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();
Mitja Bonca
Nearly a Posting Maven
2,485 posts since May 2009
Reputation Points: 641
Solved Threads: 474
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: