ListBox Question

Hi,

I am trying to load sqlite data into a ListBox so that the same recordset will fill multiple columns of the list box.

I want to load 40 records into each column . When the first 40 are filled, I would like it to jump to the first row of the second column an fill that column. I will have about 5 columns total.

I can load the first 40 rows just fine with the code below, but when I start to load the second column the data is placed in the next row (41st row), instead of going up and starting at the first row of the second column.

In the code below I know I am calling for the LastIndex and that is why it is continuing on the next row, but what is the code for telling the Listbox to go back up and start filling column 2 at the top row. Is there a way to do that? I don’t see anything in the documentation, or I’m just not looking in the right spot. Any ideas would be appreciated.

[code] While Not rs.eof

txtMember.Text=(rs.Field("Members").StringValue)

X = X + 1

List1.AddRow

If X < 41 Then
  List1.Cell(List1.LastIndex,0)=txtMember.Text
  rs.MoveNext
  
  elseIf  X > 40 And X < 81 Then
  List1.Cell(List1.LastIndex,1)=txtMember.Text
  rs.MoveNext
  
Else 
  Exit
End If

wend
[/code]

row=0
col=0
While Not rs.eof
    
    txtMember.Text=(rs.Field("Members").StringValue)
if row<41 and col=0 then List1.AddRow
    if row>=41 then 
row=0
col=col+1
end if
      List1.Cell(row,col)=txtMember.Text
      rs.MoveNext
     
    
  wend

try something like this… .NOT TESTED (off the top of my head)

Thanks Dave for steering me in the right direction. I modified your code and this works. I really appreciate you taking the time to help.

[code]Dim X as Integer
X = 0

Dim Row as Integer
Dim Col as integer

Row=0
Col=0

While Not rs.eof
X = X + 1

If X = 41 Then
  Col=1
  Row=0
  
Elseif X = 81 Then
  Col=2
  Row=0
End If

txtMember.Text=(rs.Field("Members").StringValue)

List1.AddRow
List1.Cell(Row, Col)=txtMember.Text
rs.MoveNext
Row=Row + 1

wend[/code]

Try it with

col = i \\ 40 // integer division row = i Mod 40 // remainder