ListBox - cell data type and column calculation

Hi, guys,

I have a ListBox with three columns. The first column contains text, and the other two contain numbers.

How can I:

  1. allow only numbers in the the column 2 and column 3
  2. calculate the total of all cells in column 2, and in a similar way in column 3

Thank you,

Val

1… depends on how you are getting the data to the cell… if programmatically then just reject non-numeric values, if user input, modify the keydown of active cell to only accept numeric characters

  1. loop thru the cells in each column and add them up… and then it depends on where you want to put the “answer”

Got it.

I created a timer and placed this code into it.


dim sum as double
dim Column as Integer = 0
for row as integer = 0 to ListBox1.ListCount-1
  sum = sum + val(ListBox1.cell(row, 1))
next

Label1.Text=str(sum)

It loops through the cells and parses the result into the label.

[quote=470901:@Val Kozmenko]Got it.

I created a timer and placed this code into it.


dim sum as double
dim Column as Integer = 0
for row as integer = 0 to ListBox1.ListCount-1
  sum = sum + val(ListBox1.cell(row, 1))
next

Label1.Text=str(sum)

It loops through the cells and parses the result into the label.[/quote]

Better use String.ToDouble instead of Val.

Thank you, Stefan.

I will need to wrap my head around it.

Thank you,

Val