Solved

FlexGrid.

Posted on 2000-04-25
11
1,260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

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…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

615 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