Delete column in MSFlexGrid

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.
AlexEspinalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
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
AlexEspinalAuthor Commented:
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
ajgilbertCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Éric MoreauSenior .Net ConsultantCommented:
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
Stephen MandersonSoftware EngineerCommented:
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
AlexEspinalAuthor Commented:
MrManderson: I want to delete a full column, not row.

Thanks anyway.
0
Stephen MandersonSoftware EngineerCommented:
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
Éric MoreauSenior .Net ConsultantCommented:
have you tried my code?
0
ajgilbertCommented:
Or indeed mine ?

0
Éric MoreauSenior .Net ConsultantCommented:
ajgilbert, if you have a huge grid, it can be a long to process!
0
AlexEspinalAuthor Commented:
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
ajgilbertCommented:
Emoreau, have you tested your solution ?

0
Éric MoreauSenior .Net ConsultantCommented:
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
AlexEspinalAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.