Solved

FlexGrid.

Posted on 2000-04-25
11
1,256 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 20 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

809 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