Solved

DataGridView Selected cell C#

Posted on 2009-04-14
3
703 Views
Last Modified: 2013-12-17
Hi, this is my first time dealing with selected cell in the datagridview.

My scenario is I have a datagridview1 which read from a Oracle database.
It'll list out the data inisde the selected item(so i might have 2 rows or 6 rows depending on the selected data.)

My question is can I make it in a way the user selects a row and press a button then it'll pass the value of column 1 inisde the selected row of datagridview1 So I can use it in another function.Something like Selected.Tag in treeview.

I'd appreciate if you could tell me which event to use.Thanks.
0
Comment
Question by:csharp_learner
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24135934
to get col1 value of selected row:

var col1val = DataGriidView.Item(Column1,SelectedRow).Value;
0
 

Author Comment

by:csharp_learner
ID: 24135972
Thanks for your reply,

Do I need to bind the datagridview to an event for this?
I'm letting the user to use the click button, So how can i access to the
"var col1val = DataGriidView.Item(Column1,SelectedRow).Value;"
from the button_click function?
0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 400 total points
ID: 24136226
You can access the selected row Col1 value from button_click as follows:

       private void button1_Click(object sender, EventArgs e)
        {
            string value = dataGridView1.CurrentRow.Cells[0].Value.ToString();
        }
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question