• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

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.

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        
        .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!
1 Solution
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

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
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

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Just add MSHFlexGrid1.rows = 0 before adding entries.

Hope this help
VortexoAuthor Commented:
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???

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now