Solved

FlexGrid.

Posted on 2000-04-25
11
1,254 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
Comment Utility
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 20 total points
Comment Utility
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
Comment Utility
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
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
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
Comment Utility
HAHA, Thanks man.
0
 
LVL 14

Expert Comment

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

Expert Comment

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

Semper Fi
0
 
LVL 6

Author Comment

by:Marine
Comment Utility
Your welcome bud :)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now