MsFlexGrid Control

Discussion in 'AutoCAD' started by Matthew, Jun 8, 2004.

  1. Matthew

    Matthew Guest

    Any one know where I could get some good examples of how to use this
    control? I am having some problems. If I set the colwidth property at
    runtime I can't put anything in the cells. Second, how do I reset the number
    of rows so that I can put data in the list from a different source? Maybe a
    little background information would be in order here. I'm using the
    FlexGrid to list a set of layer names, colors, & Linetypes from an excel
    spread sheet. with the fore color of the cell being set to the layer color.
    My last question, how do I get the vale/index of the selected cells?

    Thanks
    Mathew
     
    Matthew, Jun 8, 2004
    #1
  2. First, I assume you are using full vb6, riight? If not, you cannot use the
    flexgrid in vba per your MS EULA.

    Second, I never use it :) Look into either SGrid from vbAccelerator.com, or
    ubGrid or BeeGrid [if you can still find a download]. They are all freeware
    grid controls that can be used in vb or vba and have better control than
    the flexgrid. If you go to CADlyst's website, there is an example using
    SGrid that I wrote for the May-June CAD Clinic columns [2 parter] that
    should answer all your q's if you decide to use SGrid.

    I realize this doesn't exactly answer your question but you're better off
    not messing with the flexgrid.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jun 9, 2004
    #2
  3. Matthew

    wivory Guest

    Umm...where're the CAD Clinic columns please Mike? I had a bit of a look around the CADalyst site but couldn't find 'em.

    Thanks

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jun 9, 2004
    #3
  4. Matthew

    Jürg Menzi Guest

    Using ADO with Access, 4 fields from an Access table, first column is key
    value (AutoInc) and not visible...
    <snip>
    'Declaration:
    Dim AdbCon As New ADODB.Connection
    Dim AdbCmd As New ADODB.Command
    Dim AdbRec As New ADODB.Recordset
    Dim SelInc As Long
    '------------------------------------------------------------
    'Form Initialize:
    Dim ArrCnt As Integer
    Dim ColCap(0 To 3) As String
    Dim ColWdt(0 To 3) As Integer

    ColCap(1) = "Header 1"
    ColCap(2) = "Header 2"
    ColCap(3) = "Header 3"
    ColWdt(0) = 0
    ColWdt(1) = 50
    ColWdt(2) = 105
    ColWdt(3) = 105

    With AdbCon
    .Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Password=;" & _
    "Persist Security Info=True;" & _
    "Data Source=" & "YourDatabasePathAndName"
    .CursorLocation = adUseClient
    End With

    With AdbCmd
    .ActiveConnection = AdbCon
    .CommandType = adCmdUnknown
    .CommandText = "SELECT * FROM YourTable"
    End With
    With AdbRec
    .CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open AdbCmd
    End With
    Set grdUser.DataSource = AdbRec
    With grdUser
    For ArrCnt = 0 To UBound(ColCap)
    With .Columns(ArrCnt)
    .Caption = ColCap(ArrCnt)
    .Width = ColWdt(ArrCnt)
    End With
    Next ArrCnt
    End With
    See ClearFields, ReBind, HoldFields methodes
    In grdUser_RowColChange and grdUser_Click event:
    <snip>
    SelInc = AdbRec.Fields("AutoInc")
    <snip>

    Cheers
     
    Jürg Menzi, Jun 9, 2004
    #4
  5. Matthew

    Matthew Guest

    I downloaded the VB5 version. That is the version I have. But I can't add
    it to a form in VBA. Are you telling me that I can only use it in VB? The
    examples you posted don't work either.

    I'm looking for other grid controls on the internet. I don't know enough
    about VB to make my own control.

    Any other good suggestions?

    Thanks
    Matthew
     
    Matthew, Jun 9, 2004
    #5
  6. Matthew

    jem Guest

    I have spent a good deal of time trying to get grid controls working in VBA
    with a database connection to fill the rows and columns. My conclusion was
    that it was not possible. I think you would have to pay for a professionally
    written control. The free ones and MSFLEXGRID don't work in VBA (especially
    if you are trying to hook them up to a database). I can't remember if I
    tried without a database connection.

    My advice is to pay for one that is tested with VBA or use another solution
    (eg. multiple column listbox). Don't waste time with the grid controls. Most
    grid controls were designed for VB only and not VBA.

    Greg
     
    jem, Jun 10, 2004
    #6
  7. Matthew

    Jürg Menzi Guest

    Hi Matthew
    I use MSGrid/FlexGrid in a lot of different apps. I never had problems to use
    this control in AutoCAD's VBA - but - as Mike mentioned you need full vb6.
    Wasting money?

    Cheers
     
    Jürg Menzi, Jun 10, 2004
    #7
  8. The GRID controls I mentioned work fine in VBA. BeeGrid will connect
    directly to datasource. Some of the others might not - I'm not sure off the
    top of my head. Worst case is you:

    1. run a sql query thru odbc
    2. iterate and add the returned dataset to a scripting dictionary or
    collection
    3. use the dictionary/collection to populate the grid control

    I do it all the time, so either you have been trying to do something
    unsupported like using a data control and trying to attach it to the grid,
    or you need to learn more about data access. Bottom line is you do NOT have
    to buy a control! The free controls may require more coding, which is a
    trade off for being freee, but they woork fine

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jun 10, 2004
    #8
  9. I downloaded the VB5 version. That is the version I have. But I can't add
    Not sure what you are asking Matthew? If you are asking can the Flexgrid
    only be used in full vb, the answer is YES!
    My examples are VBA6 which should work fine in AutoCAD 2002+ because tthey
    are VB6. If you are using an AutoCAD less than 2002, simply change any
    missing references and step thru the program and fix whatever fails. For
    example, I know I use the SPLIT command but there is a custom VB5 command
    that mimics its functionality. Do a google for something like that.
    You stated you have VB5 - full or vba? If full, why are you screwing around
    with vba? Just write a DLL that AutoCAD accesses.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jun 10, 2004
    #9
  10. Actually here is the link to a version of BeeGrid: http://tinyurl.com/3e8dl

    For background, beegrid was made by Stinga, then was sold to DataDynamics
    and renamed #Grid. It is no longer free so if you use it a lot you can buy
    it. Beegrid can still be used just fine in vb/a6 environments.

    No offense, but if you can't get this one to work with a database you have
    two choices - hang up the programming or go take some serious classes.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jun 10, 2004
    #10
  11. Matthew

    Matthew Guest

    Jürg Menzi,
    Thanks for you help, I appreciate it.
    I may have miss spoke here. I would Like to get a list of the highlighted
    cells. I am using the flexgrid as a glorified listbox. in which I can make
    the font color match the layer color. I don't have a DataSource, I manually
    populate the grid.


    Thanks again
    Matthew
     
    Matthew, Jun 14, 2004
    #11
  12. Matthew

    Jürg Menzi Guest

    Hi Matthew

    Tere is something to play with:
    ' -----
    Private Sub UserForm_Initialize()

    Dim RowCnt As Integer
    Dim ColCnt As Integer
    Dim MaxRow As Integer
    Dim MaxCol As Integer
    Dim CelCol As Long

    MaxCol = 5
    MaxRow = 10
    CelCol = 65280

    With MSFlexGrid1
    .Cols = MaxCol + 1
    .Rows = MaxRow + 1

    For RowCnt = 1 To MaxRow
    For ColCnt = 1 To MaxCol
    .Col = ColCnt
    .Row = RowCnt
    .Text = CStr(ColCnt) & "/" & CStr(RowCnt)
    .CellBackColor = &H80000012
    .CellForeColor = CelCol
    CelCol = CelCol + 300000
    Next ColCnt
    Next RowCnt
    End With

    End Sub
    ' -----

    Cheers
     
    Jürg Menzi, Jun 15, 2004
    #12
  13. Matthew

    jem Guest

    "No offense" and then you go on to write something offensive. Maybe you
    should take some classes on manners. If you have a different opinion then
    state it but don't make it personal.

    I have tried using some of Microsoft's grids in both VB and VBA and I was
    quite successful in VB but had no success in VBA. As I recall I could get
    the data to display in the grid but was not successful in allowing the user
    to modify the data and have it update the database (but it was some time ago
    so I may be recalling incorrectly).

    I also found that many books written on these subjects don't give a very
    good explanation of all the various methods of connections and the format of
    the commands. They give a few simple examples but don't go on to explain in
    detail. So when you have something more complicated in mind you are on your
    own.

    If you have some "useful" information please feel free to share it.

    Greg
     
    jem, Jun 17, 2004
    #13
  14. "No offense" and then you go on to write something offensive. Maybe you
    Sorry, if you chose to take offense that's your issue not mine. As I
    stated you don't need to pay for a grid if you know what you are doing. Did
    you even try the BeeGrid control? Had you tried it and got it to work, you
    wouldn't have replied.
    That's because you cannot use the grid controls in VBA - as I stated very
    early on
    go to your local library or the discussion groups on MSDN - there they have
    specific groups for different types of data access
    I've given you lots wthin this thread - its yours to do with as you will

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Jun 17, 2004
    #14
  15. Matthew

    jem Guest

    Sorry, if you chose to take offense that's your issue not mine

    Ah, I see you have your own universe ... Isn't that the same line those guys
    in the white sheets and pointy hats always give out.
     
    jem, Jun 24, 2004
    #15
  16. Mike is one of the most stable personalities here. Where does that leave
    you?

    --
    R. Robert Bell


    Ah, I see you have your own universe ... Isn't that the same line those guys
    in the white sheets and pointy hats always give out.
     
    R. Robert Bell, Jun 24, 2004
    #16
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.