Results 1 to 10 of 10

Thread: [RESOLVED] How to add a command button to listview or msflexgrid?

  1. #1

    Thread Starter
    Member blueorange's Avatar
    Join Date
    Sep 2008
    Location
    Philippines
    Posts
    47

    Resolved [RESOLVED] How to add a command button to listview or msflexgrid?

    I had a program that will display all the countries in a list. I could use a listview or msflexgrid. My problem is how to add a command button to each rows in the listview? If it's impossible or difficult to implement this in listview, msflexgrid will do great. Does anybody know how to implement this or do you have a custom ocx that I can use? thanks for your help. Happy Holidays!!

  2. #2
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How to add a command button to listview or msflexgrid?

    Quote Originally Posted by blueorange
    I had a program that will display all the countries in a list. I could use a listview or msflexgrid. My problem is how to add a command button to each rows in the listview?
    If these buttons are going to align with each row that's going to be a lot of tiny CmdButtons. Why do you want to do this?
    Edit: Did you mean to say Columns instead of Rows? If so, the Column Headers have a Click Event and they show action, like a CommandButton, when clicked. Each Item in the list also has a click event.
    Last edited by CDRIVE; Dec 23rd, 2008 at 01:18 AM.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  3. #3

    Thread Starter
    Member blueorange's Avatar
    Join Date
    Sep 2008
    Location
    Philippines
    Posts
    47

    Re: How to add a command button to listview or msflexgrid?

    Quote Originally Posted by CDRIVE
    If these buttons are going to align with each row that's going to be a lot of tiny CmdButtons. Why do you want to do this?
    Specifically, each row of my listview (report view) has an item that represents the color of each country which was plotted in the map, the name of the country and then I want to add a button that can remove the country's assign color but not remove the country from the listview.


    Something like this:

    Color Country Option
    ====== ======== ========
    Red China Remove
    Yellow Argentina Remove

  4. #4
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: How to add a command button to listview or msflexgrid?

    I have a msflexgrid that i display a little picture that look like command buttons
    loaded from a resource file like this:

    Code:
    Set DocGrid.CellPicture = LoadResPicture(179, vbResBitmap) 
    DocGrid.CellPictureAlignment = flexAlignCenterCenter
    You can then use the click event based on the row, col clicked.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5

    Thread Starter
    Member blueorange's Avatar
    Join Date
    Sep 2008
    Location
    Philippines
    Posts
    47

    Re: How to add a command button to listview or msflexgrid?

    Quote Originally Posted by isnoend07
    I have a msflexgrid that i display a little picture that look like command buttons
    loaded from a resource file like this:

    Code:
    Set DocGrid.CellPicture = LoadResPicture(179, vbResBitmap) 
    DocGrid.CellPictureAlignment = flexAlignCenterCenter
    You can then use the click event based on the row, col clicked.

    Great. Can I use your Msflexgrid?

  6. #6
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to add a command button to listview or msflexgrid?

    I usually do something like this:

    Create two pictures. One of you button in a unclicked state. And one of the button when it is being clicked. Add two image controls to your form and set their picture property to the ones you created respectively. then set the cellpicture of that row,column to the image of the unclicked button like this:

    the following each row sets column 18 to a bvutton image:

    Code:
    Private Sub SetButtons(Optional ByVal iCol As Integer, Optional ByVal iRow As Integer)
    
      Dim x As Long
      Dim y As Long
      Dim TempRow As Long
      Dim TempCol As Long
    
        TempRow = MSFlexGrid1.Row
        TempCol = MSFlexGrid1.Col
    
        For x = 2 To MSFlexGrid1.Rows - 1
            For y = 0 To MSFlexGrid1.Cols - 1
                      If (y = 18) Then
                        MSFlexGrid1.Row = x
                        MSFlexGrid1.Col = y
                        MSFlexGrid1.CellPictureAlignment = 4 'center x center
                        Set MSFlexGrid1.CellPicture = imgUniversal.Picture
                        MSFlexGrid1.CellForeColor = &HE0E0E0
                      End If
            Next y
        Next x
        MSFlexGrid1.Row = TempRow
        MSFlexGrid1.Col = TempCol
    
    END Sub
    then on the msflexgrids click even do a check and see of column 18 was clicked and set the picture to the one of the clicked image:

    Code:
    If (MSFlexGrid1.Col = 18) Then
                    MSFlexGrid1.CellPictureAlignment = 4 'center x center
                    Set MSFlexGrid1.CellPicture = imgUniversal2.Picture  
                    DoEvents
                    Sleep (100)
                    Set MSFlexGrid1.CellPicture = imgUniversal.Picture
    end if
    you can code whatever needs to happen in this click event.

  7. #7
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: How to add a command button to listview or msflexgrid?

    Quote Originally Posted by Nitesh
    I usually do something like this:

    Code:
    If (MSFlexGrid1.Col = 18) Then
                    MSFlexGrid1.CellPictureAlignment = 4 'center x center
                    Set MSFlexGrid1.CellPicture = imgUniversal2.Picture  
                    DoEvents
                    Sleep (100)
                    Set MSFlexGrid1.CellPicture = imgUniversal.Picture
    end if
    you can code whatever needs to happen in this click event.
    Since you're calling the Sleep API I think she's going to need this.
    Code:
    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  8. #8
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: How to add a command button to listview or msflexgrid?

    Quote Originally Posted by blueorange
    Great. Can I use your Msflexgrid?
    heres my grid, it's in a picturebox, you need to make your as this is specific to my needs, you can use it as a example
    Code:
    Sub orderDocGrid()
        Dim i As Integer
        Dim S As String
        DocGrid.Rows = 6
        DocGrid.Cols = 8
        
        With DocGrid
        .ColAlignment(2) = flexAlignCenterCenter
        .ColWidth(7) = 0
        .ColWidth(0) = 1280
        .TextMatrix(0, 0) = "Description"
        .Row = 0
        .Col = 0
        .CellAlignment = 4
        .CellFontBold = True
        
        For i = 0 To 5
        .RowHeight(i) = 300 
        Next i
        
        .ColWidth(1) = 1200
        .TextMatrix(0, 1) = "Amount"
        .Row = 0
        .Col = 1
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(0, 2) = 1060
        .TextMatrix(0, 2) = "Date"
        .Row = 0
        .Col = 2
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(3) = 790
        .TextMatrix(0, 3) = "Printed"
        .Row = 0
        .Col = 3
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(4) = 1120
        .TextMatrix(0, 4) = "Create/See"
        .Row = 0
        .Col = 4
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(5) = 920
        .TextMatrix(0, 5) = "Number"
        .Row = 0
        .Col = 5
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(6) = 920
        .TextMatrix(0, 6) = "Emailed"
        .Row = 0
        .Col = 6
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .TextMatrix(4, 5) = "na"
        
        .TextMatrix(1, 0) = "Proposal"
        .TextMatrix(2, 0) = "Change Order"
        .TextMatrix(3, 0) = "Invoice"
        .TextMatrix(4, 0) = "Letter"
        .TextMatrix(5, 0) = "Certification"
        .TextMatrix(4, 1) = "na"
        .TextMatrix(5, 1) = "na"
       End With
        For i = 0 To 4
       DocGrid.ColAlignment(i) = 4
       Next i
       For i = 1 To 5
       DocGrid.Row = i
       DocGrid.Col = 0
       DocGrid.CellAlignment = flexAlignLeftCenter
       Next i
       
       DocGrid.Height = DocGrid.Rows * DocGrid.RowHeight(DocGrid.Rows - 1) + 140
       
       On Error Resume Next
       Dim w As Long
       i = 0
        For i = 0 To DocGrid.Cols - 1
            w = w + DocGrid.ColWidth(i) + 125
            Next i
        DocGrid.Width = w
       
       PicCreateDocuments.Height = DocGrid.Height + DocGrid.Top + 100
         
         Me.PicCreateDocuments.Width = w + 200
         Me.cmdCloseDocManager.Left = PicCreateDocuments.Width - (cmdCloseDocManager.Width + 95)
         Me.lblDocumentManager.Left = PicCreateDocuments.Width / 2 - lblDocumentManager.Width / 2
    
    For i = 1 To 5 
            Me.DocGrid.Col = 4
            Me.DocGrid.Row = i
             Set DocGrid.CellPicture = LoadResPicture(182, vbResBitmap) '182= button
            Me.DocGrid.CellPictureAlignment = flexAlignCenterCenter
           Next i
         
         
        
        End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  9. #9

    Thread Starter
    Member blueorange's Avatar
    Join Date
    Sep 2008
    Location
    Philippines
    Posts
    47

    Re: How to add a command button to listview or msflexgrid?

    Quote Originally Posted by isnoend07
    heres my grid, it's in a picturebox, you need to make your as this is specific to my needs, you can use it as a example
    Code:
    Sub orderDocGrid()
        Dim i As Integer
        Dim S As String
        DocGrid.Rows = 6
        DocGrid.Cols = 8
        
        With DocGrid
        .ColAlignment(2) = flexAlignCenterCenter
        .ColWidth(7) = 0
        .ColWidth(0) = 1280
        .TextMatrix(0, 0) = "Description"
        .Row = 0
        .Col = 0
        .CellAlignment = 4
        .CellFontBold = True
        
        For i = 0 To 5
        .RowHeight(i) = 300 
        Next i
        
        .ColWidth(1) = 1200
        .TextMatrix(0, 1) = "Amount"
        .Row = 0
        .Col = 1
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(0, 2) = 1060
        .TextMatrix(0, 2) = "Date"
        .Row = 0
        .Col = 2
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(3) = 790
        .TextMatrix(0, 3) = "Printed"
        .Row = 0
        .Col = 3
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(4) = 1120
        .TextMatrix(0, 4) = "Create/See"
        .Row = 0
        .Col = 4
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(5) = 920
        .TextMatrix(0, 5) = "Number"
        .Row = 0
        .Col = 5
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .ColWidth(6) = 920
        .TextMatrix(0, 6) = "Emailed"
        .Row = 0
        .Col = 6
        .CellFontBold = True
        .ColAlignment = flexAlignCenterCenter
        
        .TextMatrix(4, 5) = "na"
        
        .TextMatrix(1, 0) = "Proposal"
        .TextMatrix(2, 0) = "Change Order"
        .TextMatrix(3, 0) = "Invoice"
        .TextMatrix(4, 0) = "Letter"
        .TextMatrix(5, 0) = "Certification"
        .TextMatrix(4, 1) = "na"
        .TextMatrix(5, 1) = "na"
       End With
        For i = 0 To 4
       DocGrid.ColAlignment(i) = 4
       Next i
       For i = 1 To 5
       DocGrid.Row = i
       DocGrid.Col = 0
       DocGrid.CellAlignment = flexAlignLeftCenter
       Next i
       
       DocGrid.Height = DocGrid.Rows * DocGrid.RowHeight(DocGrid.Rows - 1) + 140
       
       On Error Resume Next
       Dim w As Long
       i = 0
        For i = 0 To DocGrid.Cols - 1
            w = w + DocGrid.ColWidth(i) + 125
            Next i
        DocGrid.Width = w
       
       PicCreateDocuments.Height = DocGrid.Height + DocGrid.Top + 100
         
         Me.PicCreateDocuments.Width = w + 200
         Me.cmdCloseDocManager.Left = PicCreateDocuments.Width - (cmdCloseDocManager.Width + 95)
         Me.lblDocumentManager.Left = PicCreateDocuments.Width / 2 - lblDocumentManager.Width / 2
    
    For i = 1 To 5 
            Me.DocGrid.Col = 4
            Me.DocGrid.Row = i
             Set DocGrid.CellPicture = LoadResPicture(182, vbResBitmap) '182= button
            Me.DocGrid.CellPictureAlignment = flexAlignCenterCenter
           Next i
         
         
        
        End Sub
    thank you, this really helps.

  10. #10
    New Member
    Join Date
    Aug 2009
    Location
    Gloucester, UK
    Posts
    2

    Re: [RESOLVED] How to add a command button to listview or msflexgrid?

    Thanks you isnoend07 - your code helped me too!

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width