Click here to Skip to main content
15,913,685 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
How can I get the value of a column from a grid view when check box is checked.

Please any one help me.
Posted
Updated 21-Feb-11 22:21pm
v2
Comments
Dalek Dave 22-Feb-11 4:21am    
Edited for Grammar.

Hi,
first of all you need to react on the "Click" Event of your check box.
You know how you do?

Then I would use Row and Columns methods from DataGridView class.


Maybe also try something like this:
MIDL
dataGridView->Rows[ myRow ]->Cells[ myCell ]->Value

to get the value of a certain cell. In C# use
MIDL
dataGridView.Rows[ myRow ].Cells[ myCell ].Value



See also:
http://msdn.microsoft.com/en-en/library/system.windows.forms.datagridview.rows(v=VS.80).aspx[^]

and

http://msdn.microsoft.com/de-de/library/system.windows.forms.datagridview.columns(v=VS.80).aspx[^]
 
Share this answer
 
Comments
Sandeep Mewara 21-Feb-11 3:15am    
Good answer n links.
Dalek Dave 22-Feb-11 4:21am    
Good Call.
C#
int id;
for (int i = 0; i < grdDisplayAll.Rows.Count; i++)
{
  //Assume that 0th Row of grid named grdDisplayAll contains Checkbox
  if (Convert.ToBoolean(grdDisplayAll.Rows[i].Cells[0].Value) == true)
  {
    id = grdDisplayAll.Rows[i].Cells["Id"].Value;
    //You may use columnIndex of column instead of ColumnName (i.e. Here "Id")

    //Code here to make whatever you want to perform on selected record
  }
}

:)
Mark as Answer if it is helpful to you.. ;)
 
Share this answer
 
Comments
Dalek Dave 22-Feb-11 4:22am    
Good Answer.
Dave Paras 23-Feb-11 23:23pm    
Thanks Dave
for (int i = 0; i &lt; grvTableNames.RowCount - 1; i++)
{
if (Convert.ToBoolean(grvTableNames.Rows[i].Cells[0].EditedFormattedValue))
{
string tableName = dataTable.Rows[i][alias].ToString();
wordDataTable = businessLogic.GetTableAttibutes(name, tableName);
wordDataTable.TableName = tableName;
ds.Tables.Add(wordDataTable);
}
}


Hope this will be helpful for you.
 
Share this answer
 
Hi rahat220,

You can click a button for doing that :

private void button3_Click(object sender, EventArgs e)
{
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if (dataGridView1.Rows[i].Cells["DataGridView1_CheckBoxColumn"].Value != null && bool.Parse(dataGridView1.Rows[i].Cells["DataGridView1_CheckBoxColumn"].Value.ToString()))
        {
            // You can insert your code for getting each row data here
        }
    }
}



I hope this help,
:)
 
Share this answer
 
Comments
Dalek Dave 22-Feb-11 4:24am    
Good Answer.
This[^] might help you.
 
Share this answer
 
Comments
Dalek Dave 22-Feb-11 4:24am    
Good Link
thank you for your reply .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900