Link to home
Start Free TrialLog in
Avatar of Vortexo
Vortexo

asked on

How do you completely clear a flex grid?

Hi there! I have a simple, but confusing VB app here. It contains 1 combobox and a flex grid. When a selection is made within the combobox, the flex grid fills with data from the a database. The problem is when I select another choice, the flex grid does clear and inserts the new data, BUT there is so many empty rows.

Example:
Choice 1 has 5 items
Choice 2 has 10 items

when the first choice is made, its perfect. I see 5 items and no extra rows. Now, when I select choice 2, I do see the 10 items, but now there is 5 empty rows at the end. Can someone help me in this coding. This is what I have(I will not show database connection, thats ok).

Public combobox_click()

With MSFlexGrid1
      .Row = 0
      .Col = 0
      .Text = "STORE"
   
       i = 0
      Do Until myRec.EOF = True
         i = i + 1
         .AddItem ""
         .Col = 0
         .Row = i
         .Text = myRec!Store        
         myRec.MoveNext
      Loop    
 
        .RemoveItem (.Rows)   <--this eliminates an empty row that just appears after the last item//
       
        If use = 1 Then    <--If the combo box has been used already, delete the extra empty cells the first choice left behind//
           For x = 1 To i Step 1
              .RemoveItem (.Rows)
           Next x
        End If      
     x = 0
   End With

I also tried flexgrid.clear, but like i said, it doesn't remove the rows, just clears the text. Help please!
Avatar of AdamAnderson
AdamAnderson

Select the FlexGrid in the properties window and give it an index of 0 (zero)

Then in your code replace MSFlexGrid1 with MSFlexGrid1(0)
When you want to clear it type
    Unload MSFlexGrid1(0)
    Load MSFlexGrid1(0)
This should do it.
dim i as integer

i=1
Do While Not objr.EOF
        If i <> 1 Then
            MSHFlexGrid1.Rows = MSHFlexGrid1.Rows + 1
        End If

'   load your datas here and put them in the grid.
       
        i = i + 1
       
       objr.MoveNext
Loop
it works perfectly for me
It may be happening because your msflex.rows property not initialized again when you change item in combo and it add more 10 rows .
so make clear whenever you insert new record as per combo value each time reset Rows property ,may be
  msflex.rows=2 or 1 ,as you want

hope this may help you
ASKER CERTIFIED SOLUTION
Avatar of xThorx
xThorx

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 Vortexo

ASKER

Thank you xThorx, I knew it was a simple missing syntax. And for you other guys, thanx for the support. Your comments gave me errors which I could not work around.
vortexo don't u think that my solution is more detailed as per your problem and i also posted it before then y i not  got the points???