how to select data row FRom MSHflexgrid?-VBForums
Results 1 to 31 of 31

Thread: how to select data row FRom MSHflexgrid?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Resolved how to select data row FRom MSHflexgrid?

    good day every body
    i make MSHflexgrid and connected it by database to show data.....

    but now if i need to change some data in database by MSHflexgrid show......
    i mean if i have MSHflexgrid and select any row by Click and next press A command to open form include the data which i select it from MSHflexgrid........ so how we can make this

    thanks
    Last edited by Suzoki; Sep 14th, 2017 at 07:53 AM.

  2. #2
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: how to select data row FRom MSHflexgrid

    Suzoki

    Could you post a screenshot of what your your form looks like so far?

    Spoo

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    ?HUH?
    You can use MSFlexgrid1.TextMatrix(x,y) where x is the row number, and y is the column number. (Remember, it is 0-based). SO, if you click on a cell in row 5, for example, and that cell is in column 3, then whatever value in that cell is shown by MSFLexgrid1.TextMatrix(5,3). Then, all you have to do is update your database (presumably on a Command Button click event) using that value.

    EX

    Code:
    Dim mString as String
    Grid1_click()
    sString = grid1.TextMatrix(grid1.Row, grid1.Col)
    end sub
    command1_click()
    'update your database here using sString as the value you want to update
    end sub
    Without seeing ANY of your code, it is hard to provide precise assistance.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by Spooman View Post
    Suzoki

    Could you post a screenshot of what your your form looks like so far?

    Spoo
    Name:  1.jpg
Views: 67
Size:  16.5 KB

    When i select any row from Grid and press Edit Command Button then appear form include the data in MShflexgrid row
    Last edited by Suzoki; Sep 7th, 2017 at 03:27 PM.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Thanks SAmOScarBrown I attached up Picture....... I hope it will be Clear

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    C'mon Su....try SOMETHING...I gave you great hints. Let's see what YOU do based upon those hints. Maybe others will w-r-i-t-e i-t o-u-t f-o-r y-o-u, but I prefer to see some sort of effort on YOUR part here. I'll help if you get stuck.

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    3,287

    Re: how to select data row FRom MSHflexgrid

    Way to go, Sam.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    ok Sam i will try and tell you

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by SamOscarBrown View Post
    C'mon Su....try SOMETHING...I gave you great hints. Let's see what YOU do based upon those hints. Maybe others will w-r-i-t-e i-t o-u-t f-o-r y-o-u, but I prefer to see some sort of effort on YOUR part here. I'll help if you get stuck.
    sam this code is success with me thanks
    but i need some thing else...... when user select cell from grid i need all row which included the selected cell mark with any color can get this
    thanks

  10. #10
    PowerPoster
    Join Date
    Oct 2013
    Posts
    2,917

    Re: how to select data row FRom MSHflexgrid

    Check the help of the MSFlexGrid control, there are properties for dealing with background/foreground color of a cell.

  11. #11
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    743

    Re: how to select data row FRom MSHflexgrid

    Hi ,
    you can show somthing like Edit

    sample
    Code:
     Private mlngID As Long
    
    Private Sub Command2_Click()
    Dim iSelected As Integer
        With MSFlexGrid1
            iSelected = .Row
                .Col = 0
               .ColWidth(0) = 900
                .CellForeColor = vbBlue
                .Text = .Text & " (Edit)"
           'your Code here to load the row (Val(iSelected))
            End With
        On Error Resume Next
       mlngID = iSelected
    
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  12. #12
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    You can set the cell back color for the entire row by iterating through each column for that row:

    Ex:

    Code:
    Private Sub MSFlexGrid1_Click()    Dim iCol As Integer
        For iCol = 0 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = iCol
            MSFlexGrid1.CellBackColor = vbRed
        Next iCol
    End Sub

  13. #13

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by SamOscarBrown View Post
    You can set the cell back color for the entire row by iterating through each column for that row:

    Ex:

    Code:
    Private Sub MSFlexGrid1_Click()    Dim iCol As Integer
        For iCol = 0 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = iCol
            MSFlexGrid1.CellBackColor = vbRed
        Next iCol
    End Sub
    thanks but if i change the focus to the another Row the color of the last row i selected it still appear ..... i want disappear and back to default i try to add some code to yours code but not success
    Code:
    Private Sub MSFlexGrid1_Click()    Dim iCol As Integer
        MSFlexGrid1.BackColor=VBWhite
        For iCol = 0 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = iCol
            MSFlexGrid1.CellBackColor = vbRed
        Next iCol
    End Sub
    Last edited by Suzoki; Sep 8th, 2017 at 08:04 AM.

  14. #14
    PowerPoster
    Join Date
    Oct 2013
    Posts
    2,917

    Re: how to select data row FRom MSHflexgrid

    The .CellBackColor is set for the current .Row and .Col
    If you want to restore the colors you have to know the previous .Row and .Col, set to the .BackColor property and then set the backcolor of the current .Row and .Col

  15. #15
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    well, think about it.

    This is how, in pseudo code:

    Iterate through every row, (go from grid rows 0 to grid1.rows -1),
    change cell back colors to white (vbWhite) for each row (same as I changed that ONE selected row to vbRed),
    then continue with my code.

    You will have a for-loop within a for-loop, like

    Code:
    for x = 0 to grid1.rows -1
        for y = 0 to grid1.cols -1
            change each cell in each row to vbWhite here
        next y
    next x
    then do my code here

  16. #16
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    Well, I gotta run....just so you won't be trying this all day and not getting there (and I HATE to do this, but I want to help you...please LEARN from this (SAVE this somewhere so you can refer to it when you forget how to do it in the future)):

    Example:

    Code:
    Private Sub MSFlexGrid1_Click()    Dim iCol As Integer
        Dim iRow As Integer
        For iRow = 0 To MSFlexGrid1.Rows - 1
            MSFlexGrid1.Row = iRow
            For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbWhite
            Next iCol
        Next iRow
        MSFlexGrid1.Row = MSFlexGrid1.MouseRow
        For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbYellow
            Next iCol
    End Sub

  17. #17

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by SamOscarBrown View Post
    Well, I gotta run....just so you won't be trying this all day and not getting there (and I HATE to do this, but I want to help you...please LEARN from this (SAVE this somewhere so you can refer to it when you forget how to do it in the future)):

    Example:

    Code:
    Private Sub MSFlexGrid1_Click()    Dim iCol As Integer
        Dim iRow As Integer
        For iRow = 0 To MSFlexGrid1.Rows - 1
            MSFlexGrid1.Row = iRow
            For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbWhite
            Next iCol
        Next iRow
        MSFlexGrid1.Row = MSFlexGrid1.MouseRow
        For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbYellow
            Next iCol
    End Sub
    thanks SAM i already try this code but there is problem this code will be always make last row for Grid yellow not the row which i selected
    Because first nested for change the value of cell which i selected to the last cell so i change code to this
    Code:
    Dim R As Long
    Dim C As Long
    Dim RW As Long
    Dim CL As Long
        RW = MSHFlexGrid1.Row
        For CL = 0 To MSHFlexGrid1.Cols - 1
            MSHFlexGrid1.Col = CL
            MSHFlexGrid1.CellBackColor = vbRed
        Next
        For R = 0 To MSHFlexGrid1.Rows - 1
            If R <> RW Then
                For C = 0 To MSHFlexGrid1.Cols - 1
                    MSHFlexGrid1.Row = R
                    MSHFlexGrid1.Col = C
                    MSHFlexGrid1.CellBackColor = vbWhite
                Next
            End If
        Next

  18. #18

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    By the way i found some properties in MSHflexgrid called Selection mode if we choice :flex selection by row it will choice automatically all row also we can change color in BackcolorSel Properties so we didn't need to make any code
    thank's for all

  19. #19
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    this code will be always make last row for Grid yellow not the row which i selected
    No it doesn't. It works just fine as "I" typed it.

    You did something wrong.

  20. #20

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by SamOscarBrown View Post
    No it doesn't. It works just fine as "I" typed it.

    You did something wrong.
    yes you are right.... in second FOR i type MSHfflexgrid.row ........ it must be as you type MSHfflexgrid.mouserow
    thanks for you help

  21. #21
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    Do you understand why it is mouserow and not row?

  22. #22
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: how to select data row FRom MSHflexgrid

    Yikes !!
    I'm interested in knowing his reply, but I can say right now that I, for one, DON'T ..

    EDIT-1

    OK, cancel that.
    I do now, but it never dawned on me that such a feature was avaliable.


    Spoo
    Last edited by Spooman; Sep 9th, 2017 at 07:26 AM.

  23. #23
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    743

    Re: how to select data row FRom MSHflexgrid

    Hi

    here a sample to color the text or/and Backcolor

    Code:
    'add Controls:  1 Flexgrid, 2 Checkboxes
    
    Option Explicit
    
    Private FlexLastRow As Long
    Private ActRowForeColor As Long
    Private ActRowBackColor As Long
    
    Private Sub Form_Load()
    
       Dim i As Long
       Dim j As Long
    
          With MSFlexGrid1
             .Rows = 30
             .Cols = 6
             .FocusRect = flexFocusLight
             .FillStyle = flexFillRepeat
             For i = .FixedRows To .Rows - 1
                For j = .FixedCols To .Cols - 1
                   .TextMatrix(i, j) = "xxxxxxx"
                Next
             Next
             FlexLastRow = 2
          End With
          ActRowForeColor = vbRed
          ActRowBackColor = vbYellow
          
          Check1.Value = 1
          Check2.Value = 1
          
          MSFlexGrid1_RowColChange
    End Sub
    
    Private Sub MSFlexGrid1_RowColChange()
    
       Dim ColorizeForeColor As Boolean
       Dim ColorizeBackColor As Boolean
       
          ColorizeForeColor = Check1.Value * -1
          ColorizeBackColor = Check2.Value * -1
    
          FlexgridColorizeRow MSFlexGrid1, FlexLastRow, ActRowForeColor, ActRowBackColor, _
                                           ColorizeForeColor, ColorizeBackColor
    End Sub
    
    'you can also put this in a Module
    Public Sub FlexgridColorizeRow(Flex As MSFlexGrid, FlexLastRow As Long, _
                                   ForeColor As Long, BackColor As Long, _
                                   Optional ColorizeForeColor As Boolean = True, _
                                   Optional ColorizeBackColor As Boolean = True, _
                                   Optional RestoreLastRow As Boolean = True)
    
       Dim Row As Long
       Dim Col As Long
       Dim ColSel As Long
       Static Working As Boolean
          If Working Then
             Exit Sub
          End If
          Working = True
          With Flex
             If .Row <> FlexLastRow Then
                .Redraw = False
                .FillStyle = flexFillRepeat
                Row = .Row
                Col = .Col
                ColSel = .ColSel
                If RestoreLastRow Then
                   .Row = FlexLastRow
                   .Col = .FixedCols
                   .ColSel = .Cols - 1
                   .CellForeColor = .ForeColor
                   .CellBackColor = .BackColor
                   .Row = Row
                End If
                .ColSel = .Cols - 1
                If ColorizeForeColor Then
                   .CellForeColor = ForeColor
                End If
                If ColorizeBackColor Then
                   .CellBackColor = BackColor
                End If
                .Col = Col
                .ColSel = ColSel
                FlexLastRow = .Row
                .Redraw = True
             End If
          End With
          Working = False
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  24. #24
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    Pretty intense. I'm thinking the following is more concise and easier to understand (and THINK it does the same as yours, Chris).

    Code:
    Option ExplicitDim iCol As Integer
    Private Sub form_load()
        SetGridCellsBackForeColor
    End Sub
    Private Sub SetGridCellsBackForeColor()
        Dim iRow As Integer
        For iRow = 0 To MSFlexGrid1.Rows - 1
            MSFlexGrid1.Row = iRow
            For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbWhite
                MSFlexGrid1.CellForeColor = vbRed
            Next iCol
        Next iRow
    End Sub
    Private Sub MSFlexGrid1_Click()
        SetGridCellsBackForeColor
        MSFlexGrid1.Row = MSFlexGrid1.MouseRow
        For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbYellow
                MSFlexGrid1.CellForeColor = vbBlack
        Next iCol
    End Sub
    Sam

  25. #25
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    743

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by SamOscarBrown View Post
    Pretty intense. I'm thinking the following is more concise and easier to understand (and THINK it does the same as yours, Chris).

    Code:
    Option ExplicitDim iCol As Integer
    Private Sub form_load()
        SetGridCellsBackForeColor
    End Sub
    Private Sub SetGridCellsBackForeColor()
        Dim iRow As Integer
        For iRow = 0 To MSFlexGrid1.Rows - 1
            MSFlexGrid1.Row = iRow
            For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbWhite
                MSFlexGrid1.CellForeColor = vbRed
            Next iCol
        Next iRow
    End Sub
    Private Sub MSFlexGrid1_Click()
        SetGridCellsBackForeColor
        MSFlexGrid1.Row = MSFlexGrid1.MouseRow
        For iCol = 0 To MSFlexGrid1.Cols - 1
                MSFlexGrid1.Col = iCol
                MSFlexGrid1.CellBackColor = vbYellow
                MSFlexGrid1.CellForeColor = vbBlack
        Next iCol
    End Sub
    Sam
    Hi Sam,

    yup , more or less

    my Code doesn't color the FixedCols, I needed this a while back when
    Users wanted CellBackcolor and/or Colored Text.

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  26. #26
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    Got it!

  27. #27
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: how to select data row FRom MSHflexgrid

    Sammi

    Speaking of the devil, I've now got it regarding MouseRow, MouseCol, and MouseMove.
    It's not witch-craft .. more like hover-craft.

    Spoo

  28. #28
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,357

    Re: how to select data row FRom MSHflexgrid

    Star Wars fan, huh?

  29. #29
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    869

    Re: how to select data row FRom MSHflexgrid

    And here I was thinking of a mundane vehicle used by Marines for beach landings.

    Talk about a double-double entendre ..
    May the Force be with You

  30. #30
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    743

    Re: how to select data row FRom MSHflexgrid

    @Sam & Spoo

    use the Force and read the Source;-))

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  31. #31

    Thread Starter
    Member
    Join Date
    Aug 2017
    Posts
    37

    Re: how to select data row FRom MSHflexgrid

    Quote Originally Posted by SamOscarBrown View Post
    Do you understand why it is mouserow and not row?
    yes of course thanks

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.