Solved

Return Cell from Selected row in datagridview

Posted on 2008-10-28
3
886 Views
Last Modified: 2013-11-26
I have a datagrid view with 8 columns.  The user selects a datarow from the table.  How do I send the cell from column2 in the selected datarow to List<string>?  Also, I want to add unique data to the List, thus if "x" already exists in the list, it will not add it again.
0
Comment
Question by:MichelleLacy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
jorgesv13 earned 500 total points
ID: 22825688
1. You can access the SelectedRow, and then the Cell.
2. You have to use the Contains method of a list

    ArrayList li = new ArrayList();
    DataGridView DataGridView1 = new DataGridView();
    if (DataGridView1.SelectedRows.Count > 0) {
        string value = DataGridView1.SelectedRows(0).Cells("Column2").Value;
        // Replace Column2 with the name of your second column
        if (!li.Contains(value)) li.Add(value); //add the value if is not yet in the list
    }

Open in new window

0
 

Author Closing Comment

by:MichelleLacy
ID: 31510919
thanks so much!!!
0
 

Author Comment

by:MichelleLacy
ID: 22833218
string value = DataGridView1.SelectedRows(0).Cells("Column2").Value;
Please note the type correction:  brackets instead of parentheses
string value = DataGridView1.SelectedRows[0].Cells["Column2"].Value;
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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