MSHFLEXGRID Additem removeitem

I have a mshflexgrid that is populated during form load using additem. I need to delete all the rows except the first row and I can do this via removeitem.
However I then need to add rows to the grid and I do this agian using additem. The problem is the items don't add to the grid unless there is a empt row.
What am I missing here.
Thanks
Whiwex
whiwexAsked:
Who is Participating?
 
ShauliConnect With a Mentor Commented:
SP^ = SP6

S
0
 
g_johnsonCommented:
with flexgrid1
    .rows = .rows + 1
    'do your additem here
end with
0
 
whiwexAuthor Commented:
that doesn't work.
After you remove a item from the grid you can't add a new item.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
ShauliCommented:
There should always be one extra row in a flexgrid in addition to the fix rows. So if you have a fix row (row zero) then row 1 should be there, empty if needed, waiting for adding items.
So, when you remove all rows, make sure to set the rows number to one above the fix lines number, right after you remove all rows.

S
0
 
whiwexAuthor Commented:
Here's a little more info
If I load the form and add 6 items to the grid using additem they are added. Then I remove 5 items from the grid using removeitem they are removed from the grid.
However If I then add 6 items to the grid only the sixth item will be add and it will be in row two. It looks like you can't start adding rows until you have added the original number of rows. Is there some kind of reset that I missing?
0
 
whiwexAuthor Commented:
The fixed rows is set to 0.
I remove all the rows but the first one or row 0.
0
 
ShauliCommented:
If the first row (row 0) is with data, as I understand it is, then the rownumber of the row you want to add would be 1 and not zero.
For that, the first thing you need to do is to find out how many rows are still there after you've removed rows, and then use the result as the row number for the next row and start counting from there.


S
0
 
whiwexAuthor Commented:
After I do the removeitems the grid.rows=1. i then add a new item andgrid.rows=2. It just doesn't add the item to the grid.
0
 
ShauliCommented:
Post your code here, so we can see what's going on.

S
0
 
samstarkeyCommented:
Why not use the following code to remove to 'items'

MsFlexGrid.Rows = 1

This will take you back to the core and you can start again

EXAMPLE

Put a form with 2 command buttons and 1 msflexgrid on.  Copy and past the follwing code

Private Sub Command1_Click()
' remove all rows but the fixed
MSFlexGrid1.Rows = 1
End Sub

Private Sub Command2_Click()
' add some rows and data after removeing the rows
For x = 0 To 7
    With MSFlexGrid1
        .AddItem "Different " & x
        .FixedCols = 0
    End With
Next x

End Sub

Private Sub Form_Load()
' add some rows and data at load
MSFlexGrid1.Rows = 1
For x = 0 To 5
    With MSFlexGrid1
        .AddItem "test " & x
    End With
Next x

'
' add button captions
Command1.Caption = "Delete Rows"
Command2.Caption = "Add Rows"


End Sub
0
 
whiwexAuthor Commented:
samstarkey
I found that code and it works. I still don't understand whats happenning with the add and remove
0
 
whiwexAuthor Commented:
Ok
msflexgrid works correctly with add and remove item
mshflexgrid does not work.
What is the difference between them?
0
 
whiwexAuthor Commented:
FOund the problem. The service pack I was using had a bug. Downloaded SP5 and it's working fine.
Thanks
0
 
ShauliCommented:
SP5????????? we are with sp^ for the last 3 years or so....


S
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.