How to get values from selected cells DataGridView C#?

How can I get to get values from selected cells DataGridView C# ? not one

i need many one , all what i selected to save in db

in windows form

i want to check every cell in the first Column and then get its value "id"

this Column is a combo box

Answers


you can use this code

    DataGridViewSelectedCellCollection DGV = this.dataGridView1.SelectedCells;
    for (int i = 0; i <= DGV.Count - 1; i++)
    {
        MessageBox.Show(DGV [i].Value.ToString());
    }

DataGridViewSelectedRowCollection t = this.theDataGridView.SelectedRows;

object theValue = this.theDataGridView.Rows[t[0].Index].Cells[index].Value;

Loop the Datagridview foreach (DataGridViewRow row in this.dataGridView1.Rows) { foreach (DataGridViewCell cell in row.Cells) { Label lbl1=new lable();

   lbl1=(label) cell.findcontrol('lbl');

}

}

find the rowindex of the selected the rows and find the controls, you will get all the selected rows.


Need Your Help

Getting image extension

java android image gallery uri

In the application the user can select an image. To start the gallery I use the following code:

Bind a NSSet representing a to-many relationship to the selection of a NSArrayController

cocoa data-binding core-data nsarraycontroller

Here's the scenario. There are two CoreData model objects, A and B, and the relationship between them is that A has-many B, represented by the property setOfBs. I'd like to display two tables, one

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.