views:

8854

answers:

8

Hello! I have a datagridview with multiple columns and rows. The first column contains a checkbox. I want the user to be able to select multiple checkboxes and then perform an action. For example if they select checkboxes in rows 1 and 2, the data from other columns in rows 1 and 2 can be selected and passed into a messagebox.

I know i need to use the checkbox_changed event to do this. However I am having trouble working out how to do this for multiple rows?

help greatly appreciated.

regards.

A: 

If you want the user to click on a button to perform the action, then what you need to handle is the Click event of the button, not the CheckBox Changed event... When the button is clicked, just go through all rows of your DataGridView and perform an action on rows with a checked checkbox.

Meta-Knight
+3  A: 

On button Click event do:

static int SelectColumnIndex = 0;
PerformAction_Click(object sender, System.EventArgs e)
{
    string data = string.Empty;
    foreach(DataGridViewRow row in MyDataGridView.Rows)
    {
      if(row.Cells[SelectColumnIndex].Value!=null &&
             Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)
      {
        foreach(DataGridViewCell cell in row.Cells)
        {
          if(cell.OwningColumn.Index!= SelectColumnIndex)
          {
            data+= (cell.Value + " ") ; // do some thing
          }
        }
        data+="\n";
      }
   }
   MessageBox.Show(data, "Data");
}
Vivek
A: 

It's not that simple.

A: 

I need you same example for gridview asp.net, thanks

peter
A: 

I need c# in datagrid controls no row selected to display message.

lingamuthu
A: 

That is the perfect solution for this problem Thanx Vivek you are a legend......Peace

Ferox
A: 

Yes It works but we need to put some conditions to work in a way we like...

jigar