Link to home
Start Free TrialLog in
Avatar of ExpressMan1
ExpressMan1Flag for Canada

asked on

C# winforms. Can I use Unbound dataGridView for calculations

Using Winforms C# SQL Server

Can a dataGridView be used unbound to enter int values for calculation purposes and then insert those values into a database table after?
I need to enter package data such as Pieces, Length, Height, Width, DimFactor on either one row or multiple rows. e.g. Length * Width * Height / Dim Factor.

All the example I found refer to bound data.

Is a dataGridView the best option for this?
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ExpressMan1

ASKER

Solved the calculation part. Here it is, just have some rounding to do.  Accepting your solution as I needed that as well. Thanks.

private void btnCalculateWeight_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView2.Rows.Count - 1; i++)
            {
                double Length;
                double Width;
                double Height;
                double DimFactor;
                double DimWeight;
                Length = Double.Parse(dataGridView2.Rows[i].Cells[2].Value.ToString());
                Width = Double.Parse(dataGridView2.Rows[i].Cells[3].Value.ToString());
                Height = Double.Parse(dataGridView2.Rows[i].Cells[4].Value.ToString());
                DimFactor = Double.Parse(dataGridView2.Rows[i].Cells[7].Value.ToString());

                Convert.ToInt32(DimWeight = Length * Width * Height / DimFactor);
                dataGridView2.Rows[i].Cells[5].Value = DimWeight;
        
            }
           
        }

Open in new window

Thank You Norie.
Avatar of Norie
Norie

No problem, sorry for not posting anything for the calculation - wasn't actually sure what you wanted to calculate.:)