How do I add Selected Cells
-
I am using a datagridview control. I want to select multiple cells that contain numbers and add them. What would be the best way to do this? Thanks.
Hello
int Sum = (int)MyDataTable.Rows[RowIndex].ItemArray[Index].Value + (int)MyDataTable.Rows[SecondRow].ItemArray[SecondIndex].Value;
And so on... Regards:rose:
-
I am using a datagridview control. I want to select multiple cells that contain numbers and add them. What would be the best way to do this? Thanks.
If I understand you right, you use DataGridView control with MultipleSelect set to true and when you select some cells you want to add numbers within them. To do that you can handle SelectionChanged event like below:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
{
//NOTE: we should check whether value in cell is a numeric value
//add values of cell
}
}BUT, be carefull to check whether selected cells has an integer value!
Vitaliy Tsvayer Tikle
-
If I understand you right, you use DataGridView control with MultipleSelect set to true and when you select some cells you want to add numbers within them. To do that you can handle SelectionChanged event like below:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
{
//NOTE: we should check whether value in cell is a numeric value
//add values of cell
}
}BUT, be carefull to check whether selected cells has an integer value!
Vitaliy Tsvayer Tikle