Link to home
Start Free TrialLog in
Avatar of AlexEspinal
AlexEspinal

asked on

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.
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

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.
Avatar of AlexEspinal
AlexEspinal

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of ajgilbert
ajgilbert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
MrManderson: I want to delete a full column, not row.

Thanks anyway.
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
have you tried my code?
Or indeed mine ?

ajgilbert, if you have a huge grid, it can be a long to process!
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.
Emoreau, have you tested your solution ?

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)
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.