Hi All

I have a unbound datagridview which i use to enter data.

I would like to make calculations using individual cell data as follows:-

Datagridview1.rows(0).cells(1).value = datagridview1.rows(1).cells(1).value + datagridview1.rows(1).cells(2).value

This works fine but if im using lots of cells it can be quite confusing .I was wondering if there was a way that i can give a cell a unique name so i can be easy for me to identify. Using the above example it could read TOTAL = JAN TOTAL + FEB TOTAL

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by Reverend Jim

Dont your have some missmatch there?
You want to have a sum from
row 1 and cell 1 +
row 1 an cell 2 =
row 0 and cell 1

Isnt this a bit strange?

Are you possitive this is it?

I would use 1st column as JAN total, 2nd column as FEB total ,.... and the last Column would be the sum from all previous columns.

Hi Thanks for your reply. I posted the example to show what i was trying to say. The cells and rows are not important i was try to find a way if we can call a cell value a unique name so i can avoid using datagridview1.rows(...).cells(...).value format .

Thanks

You can do a loop through rows:

For Each row As DataGridViewRow In dgv.Rows
row(0).Value = Integer.Parse(row(1).Value.ToString()) + Integer.Parse(row(2).Value.ToString())
Next

Explanaiton: This will show the sum of column1 and colum2 in column0 OF ALL ROWS!

Hope it helps,
bye

Edited by Mitja Bonca

You could use consts and index with those instead of literals as in

Const JAN = 1
Const FEB = 2
Const MAR = 3
.
.
.
Const TOTAL = 13
.
.
.
DataGridView1.Rows(3).Cells(JAN).Value = etc
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.