Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Delete column in MSFlexGrid

Posted on 2004-11-17
14
Medium Priority
?
466 Views
Last Modified: 2013-12-25
Hello,

I want to delete the active column in a MSFlexGrid, but have not found any property or method to do so. My be it's still too early in the morning... I suppose it's not a hard thing to do, but...

Any idea?

Thanks in advance,
Alex.
0
Comment
Question by:AlexEspinal
  • 5
  • 4
  • 3
  • +1
14 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12602826
You cannot delete a column unless it is the last one. If you want to remove the last one, you have to shift all the columns one cell to the left.
0
 

Author Comment

by:AlexEspinal
ID: 12602873
I thought it was possible to do something similar to Excel, when you right click on a column header and select Delete, and that specific column disappears.
0
 
LVL 5

Accepted Solution

by:
ajgilbert earned 200 total points
ID: 12603042
Alex,

If you want to have a go at what Emoreau has suggested above, the below is an example for an eight column (including the first fixed column) MSFLEXGRID.

Private Sub MSFlexGrid1_DblClick()
i = 0
    With MSFlexGrid1
        Do Until i = .Rows - 1
            c = .Col                                                            '  'Current' Column
            x = c + 1                                                          '  'Next' Column
            i = i + 1                                                           '   Advance Row
            Do Until x = .Cols                                   '   Loop until we reach the last row
                .TextMatrix(i, c) = .TextMatrix(i, x)       '   reset text            
               x = x + 1                                            '   Advance 'Next' column
               c = c + 1                                            '   Advance 'Current' column
            Loop
        Loop              
     .Cols = .Cols - 1                                           '   Remove 'Last' row    
     .Refresh
     End With
   
End Sub

Hope this gives you some ideas....
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12603387
a much faster way is like this:

        With mshfgMB
            If (.Cols > 2) And (mshfgMB.Col+ 1 < .Cols) Then
                Clipboard.Clear
           
                'Copy
                .Row = 0
                .Col = mintSelectedColumn + 1
                .RowSel = .Rows - 1
                .ColSel = .Cols - 1
                Clipboard.SetText .Clip
               
                'Paste
                .Row = 0
                .Col = mshfgMB.Col
                .RowSel = .Rows - 1
                .ColSel = .Cols - 2
                .Clip = Clipboard.GetText
            End If
        End With
0
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 12604423
Hi there, I have been able to delete certain rows in a flexgrid, with no problems. The way I done it was use a ID key for each row. an select the id you want to delete and the refresh the flexgrid. Works great for me,

===== Delete Button =====
Private Sub cmddelete_Click()
Call deleterow
End Sub

=====Delete Row=======
Private Sub deleterow()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset


conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database\Database.mdb;"
conn.Open



sqlstr = "Table where ID=" & ID.Text & ""

rs.Open sqlstr, conn, adOpenKeyset, adLockOptimistic

If txtID.Text = "" Then
        MsgBox "No ID Entered", vbExclamation, "Invalid ID"
With rs
   
End With rs
             .Delete
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing

'Rewrite flexgrid to changes
Call rewriteflexgrid

End Sub
0
 

Author Comment

by:AlexEspinal
ID: 12604499
MrManderson: I want to delete a full column, not row.

Thanks anyway.
0
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 12605034
O i am sorry, jumping in again, without reading the question properly. If the worse comes to it, cant you just set the coloum width to 0 effectivly revoving it from the flexgrid ? Just a sugestion. MSFlexgrid.Colwidth(1) = 0
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12605845
have you tried my code?
0
 
LVL 5

Expert Comment

by:ajgilbert
ID: 12606043
Or indeed mine ?

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12606855
ajgilbert, if you have a huge grid, it can be a long to process!
0
 

Author Comment

by:AlexEspinal
ID: 12608079
Sorry for the delay. I've been out of the office this afternoon. I'll try the code tomorrow and I'll let you know.

MrManderson, I need to take the column out of the flexgrid, not just set width to 0. Thanks for the suggestion.

Thanks to all for your time and efforts.

Alex.
0
 
LVL 5

Expert Comment

by:ajgilbert
ID: 12609077
Emoreau, have you tested your solution ?

0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 12610677
it comes from one of my project and I can insure it is working!

The only thing I have changed is mshfgMB.Col (2 places) was originally mintSelectedColumn  (and this module level variable is set in the MouseDown event)
0
 

Author Comment

by:AlexEspinal
ID: 12655298
Hi there,

I could finally test your suggestions, and I think ajgilbert's good enough for my needs, although I agree with emoreau that it would be very slow if the grid is very large. Since I just have 1 row and all I have to change is column headers, solution is good for me.

emoreau, I have awarded you points other times, but this time I haven't been able to make your code run properly.

Thanks to all for your time.

Cheers,
Alex.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

580 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