Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FlexGrid.

Posted on 2000-04-25
11
Medium Priority
?
1,263 Views
Last Modified: 2012-06-27
Hi. I am removing rows in flexgrid right after i update it. So here is what i do.I really hate this method and would like to use another one. Why do i have to Refresh the Rows ? I don't want to refresh them. If i don't do Rows - Currecnt Row i will get an error. I still don't want to use this method if anyone has it other ways please post.
I always though that i could RemoveItem Current Row this doesn't seem the case since it will result in error when it reaches the last row. My grid has 2 rows one of them is FixedRow
q = MSFlexGrid2.Rows - 1
For k = 1 To q - 1
    MSFlexGrid2.RemoveItem k
    MSFlexGrid2.Rows = q - k
    MsgBox MSFlexGrid2.Rows & "   " & k
Next
0
Comment
Question by:Marine
  • 6
  • 5
11 Comments
 
LVL 6

Author Comment

by:Marine
ID: 2749910
well the question is more this way. Why do i have to keep track of the Rows? Why don't Rows know that one row has been deleted , it's kind of stupid them not knowing that one row or other rows was gone from N Rows. Is there explanation how do you do it ?
0
 
LVL 14

Accepted Solution

by:
wsh2 earned 80 total points
ID: 2749942
1. Open a new Standard.Exe Project.
2. Add a MSFlexGrid (MSFlexGrid1).
3. Add a Command Button (Command1).
4. Copy/Paste the following into the Form1 code window.
5. Press F5 to run. All selected MSFlexgrid1 rows will be removed when the Delete Command Button is pressed.

<----- Code Begin ----->

Option Explicit

Private Sub Command1_Click()
With MSFlexGrid1
   
'  Delete All Selected Rows
   Dim intBegin As Integer
   Dim intCount As Integer
   Dim intIndex As Integer
   If .Row > .RowSel _
   Then
      intBegin = .RowSel
      intCount = .Row - .RowSel
   Else
      intBegin = .Row
      intCount = .RowSel - .Row
   End If

   For intIndex = 0 To intCount
      .RemoveItem intBegin
   Next intIndex
   
   If .Row >= .Rows _
   Then
      .Row = .Rows
   End If
   
   .RowSel = .Row
   
End With
End Sub

Private Sub Form_Load()
With MSFlexGrid1

   Command1.Caption = "Delete"

'  Load MSFlexGrid1 with Data
   .Cols = 7
   Dim lngIndex As Long
   For lngIndex = 1 To 100
      .AddItem "Row " & lngIndex & vbTab _
         & lngIndex * 10 & vbTab _
         & lngIndex * 100 & vbTab _
         & lngIndex * 1000 & vbTab _
         & lngIndex * 10000 & vbTab _
         & lngIndex * 100000 & vbTab _
         & lngIndex * 1000000 & vbTab, _
         1
   Next lngIndex
   
End With
End Sub

<----- Code End ----->
0
 
LVL 6

Author Comment

by:Marine
ID: 2749948
No WSH2 i understand that. My code works as well. But why do i have to keep the track of the Rows. Why shouldn't they do that ? When i remove the Row from the Grid it should update its rows and it should be known to them that its one less. Why must i do it .
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:wsh2
ID: 2749969
Marine.. it does keep track of the Rows. It is the Row value that never changes. I guess the reason for this is because whenever Row changes, the MSFlexgrid fires the RowColChange event procedure. Rather than guess where you want the cursor placed after a delete, it just leaves it at the last position allowing you the choice to move it.. which then fires the RowColChange Event procedure. No Move.. No Event.. I think it was pretty kewl on MS's part to code it that way.. <smile>.
0
 
LVL 6

Author Comment

by:Marine
ID: 2749977
Well it made a fool out of me today. I feel like an IDIOT that i didn't spot it. Someone had to help today to explain me that i had to keep track of it myself. Because i always though that if i remove it the rows know that its -1. And so all i would had to do is just loop though them and remove them. It doesn't seem that way. Instead i have to minus the current row to show that the row has been changed. I feel damn stupid now.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2749995
Hey.. for tonight.. don't buy guns, hear? <just kidding and LOL> Remember, we don't get mad.. we get even.. <wink>.

Semper Fi.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2750001
Oh.. and by the way.. the same thing happens when you remove items from a collection.. only worse.. as everything in the collection then has to be reindexed. When removing from collections, always delete BACK to FRONT.. the time savings is dramatic.
0
 
LVL 6

Author Comment

by:Marine
ID: 2750050
HAHA, Thanks man.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2750056
Marine:
If you are short on points.. just delete this question.. all is well by me.. <smile>
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2750061
Gawd.. you gotta be quick on the keyboard.. <sheesh>.. Thank you Marine.. <smile>.

Semper Fi
0
 
LVL 6

Author Comment

by:Marine
ID: 2750805
Your welcome bud :)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question