CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: MSFlexGrid

  1. #1
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    MSFlexGrid

    I use an MSFlexGrid with 7 rows and 10 columns. I want to display on its cells only colors and specifically only two diferent colors. When it begins I want it to be white and when the user selects an area to become blue and remain blue. When the user selects another area I want it also to remain blue and so on. Finally I want to let the user deselect an area (by dragging again) and to paint it white again. Any ideas?

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: MSFlexGrid

    Hi

    Create a form with your flexgrid on (MSFlexGrid1) and paste in the following code :


    private Sub Form_Load()
    With MSFlexGrid1
    .Rows = 7
    .Cols = 10
    .SelectionMode = flexSelectionFree
    .FixedRows = 0
    .FixedCols = 0
    End With
    End Sub

    private Sub MSFlexGrid1_MouseUp(Button as Integer, Shift as Integer, x as Single, y as Single)

    Dim lStartRow as Long
    Dim lEndRow as Long
    Dim lStartCol as Long
    Dim lEndCol as Long

    Dim lRCount as Long
    Dim lCCount as Long

    With MSFlexGrid1
    lStartRow = IIf(.RowSel < .Row, .RowSel, .Row)
    lEndRow = IIf(.RowSel < .Row, .Row, .RowSel)
    lStartCol = IIf(.ColSel < .Col, .RowSel, .Col)
    lEndCol = IIf(.ColSel < .Col, .Col, .ColSel)

    .Redraw = false
    for lRCount = lStartRow to lEndRow
    for lCCount = lStartCol to lEndCol
    .Row = lRCount
    .Col = lCCount
    If .CellBackColor = vbBlue then
    .CellBackColor = vbWhite
    else
    .CellBackColor = vbBlue
    End If
    next
    next
    .Redraw = true
    .Col = .MouseCol
    .Row = .MouseRow
    .ColSel = .Col
    .RowSel = .Row

    End With
    End Sub




    Works fine here !


    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb

  3. #3
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Nice but add these changes:

    1) Instead of vbBlue color try this: &H8000000D
    2) Also set the grid property highlight to: "always"

    P.S. I think this code has one bug: Try the selection not starting by left-up corner but by right-down. What is going on there?

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Nice but add these changes:

    I just knocked this code out for you to try - I'm certainly not going to bug-fix it as well ;-)

    I wouldn't actually use the '&H8000000D' value - try using the vb constant 'vbHighlight' - the user just might change their display settings. I used vbBlue because I'm just lazy



    >P.S. I think this code has one bug: Try the selection not starting by
    >left-up corner but by right-down. What is going on there?

    ? What do you mean ?





    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb

  5. #5
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Re: Nice but add these changes:

    You are right about the color! Thanx!
    About the bug now:
    I mean that it works well if you start dragging form the UPPER-LEFT corner. If you try to select a region from the DOWN-RIGHT corner of the region then something wrong happens... Can you try it plz?

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

  6. #6
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Nice but add these changes:

    Found it :

    My fault entirely, you need to change the 'lStartCol' line to read :


    lStartCol = IIf(.ColSel < .Col, .ColSel, .Col)





    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb

  7. #7
    Join Date
    Jul 1999
    Location
    Athens, Hellas
    Posts
    769

    Thanx! One more expansion::

    Thanx Chris! I couldn't not to rate it :-)
    Well one more expansion:
    Take a look at the following scenario:
    The user has selected some regions but when it selects a new region that contains some cells of another already selected, then it deselects the common cells. That is not desirable.

    Michael Vlastos
    Company MODUS SA
    Development Department
    Athens, Greece
    Tel: +3-01-9414900

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

Featured