Answer the question
In order to leave comments, you need to log in
How to sum cell value from selected columns of DataGridView in Label?
Hello, I'm trying to transfer the selected data from the cell to the label, when selecting a lot of cells from different rows, they do not add up, and the label is simply assigned the value of the last selected row. I don’t know how to implement the addition of different cells in the rows. Tell me what you can do please.
Tried to do like this:
foreach (DataGridViewRow row in молоко_и_молочные_продуктыDataGridView.SelectedRows)
{
d += Convert.ToDouble(row.Cells[1].Value.ToString());
label19.Text = d.ToString();
}
Answer the question
In order to leave comments, you need to log in
Well, if the topic is in TSQL, then the answer is in it
declare @s nvarchar(max) = ''
select @s = @s + Your_String_Column from Your_Table
select @s
Try like this
foreach (DataGridViewRow row in молоко_и_молочные_продуктыDataGridView.SelectedRows)
{
double number;
string value = row.Cells[1].Value.ToString();
if (Double.TryParse(value, out number))
d += number;
}
label19.Text = d.ToString();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question