all groups > vb.net controls > april 2007 >
You're in the

vb.net controls

group:

Content of the cells in a datagridview



Content of the cells in a datagridview Michel Vanderbeke
4/8/2007 7:39:21 PM
vb.net controls: Hello,

I fill a DatagridView through code as follows

Datagridview.Rows.Add(Textbox1.Text, CType(sender, Button).Text,
Textbox2.Text, Textbox1.Text * Textbox2.Text)

In Textbox1.Text and Textbox2.Text are numbers.
How can I access the content of each cell in the DatagridView?
How can I add up the numbers in a column of a datagridview in order to have
a total of the first and the fourth column?


Many thanks and greetings from Brugge (Bruges - Belgium),

Michel
Re: Content of the cells in a datagridview Tim Van Wassenhove
4/8/2007 10:09:37 PM
Michel Vanderbeke schreef:
[quoted text, click to view]

Imho you're better of defining a datasource that exposes three
properties: int Number1, int Number2 and int Total (implement the total
property as get { return this.Number1 * this.Number2; }

A sample can be seen at:
http://www.timvw.be/developing-a-datasource-for-your-datagridview/


--
RE: Content of the cells in a datagridview Daryl Saunders (Australia)
4/13/2007 2:36:00 PM
Hi Michael

I loop through the grid as follows and have a total column cmh_Debit and
cmh_Balance are constants with the column number for read ability:

For Each gr As DataGridViewRow In DataGridView1.Rows
TrnTotal = TrnTotal + gr.Cells(cmh_Debit).Value
gr.Cells(cmh_Balance).Value = TrnTotal
Next
DataGridView1.Refresh()

Hope this helps Daryl (Australia)

[quoted text, click to view]
AddThis Social Bookmark Button