Solved

FlexGrid.

Posted on 2000-04-25
11
1,255 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 75
VBA error replacing data 6 37
VB6 - Compare and highlight cell not the same 3 44
vb6 connector to mongodb 2 51
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
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…
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…

895 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