Results 1 to 10 of 10

Thread: [RESOLVED] show data in flexgrid

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Resolved [RESOLVED] show data in flexgrid

    Hi. I know i might be terrible at searching... but i dint find an answer to this :P

    I want to display all the data in the table called "Consorcios" in the flexgrid. (SELECT * FROM Consorcios)

    My link to my AccessDB is ok... if i put "MsgBox ADOrs(0)" i get the right data.
    But how to load that data in the flexgrid.

    I used this method to link:
    Private cnVar As ADODB.Connection
    Private rsVar As ADODB.Recordset

    VB Code:
    1. Set cnVar = New ADODB.Connection
    2.    cnVar.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBPath
    3.    cnVar.Open
    4.    Set rsVar = New ADODB.Recordset
    5.    rsVar.Open ObjectName, cnVar, adOpenKeyset, adLockPessimistic, ObjectType

    Dont mind the lacking data... cause this is in a function and the data is passed as parameters. Jus wanted to show you how i did this.

  2. #2
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: show data in flexgrid

    i think this can help
    VB Code:
    1. Dim RowNum As Long
    2. Dim ColNum As Long
    3. RowNum = 0
    4. MSFlexGrid1.Rows = 1
    5. MSFlexGrid1.Cols = rs.Fields.Count
    6. While Not rs.EOF
    7.     RowNum = RowNum + 1
    8.     For ColNum = 0 To rs.Fields.Count - 1
    9.         MSFlexGrid1.TextMatrix(RowNum, ColNum) = rs.Fields(ColNum).Value
    10.     Next
    11.     rs.MoveNext
    12. Wend
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  3. #3
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: show data in flexgrid

    otherwise if you want to show in a differenct order then
    VB Code:
    1. Dim RowNum As Long
    2. Dim ColNum As Long
    3. RowNum = 0
    4. MSFlexGrid1.Rows = 1
    5. MSFlexGrid1.Cols = rs.Fields.Count
    6. While Not rs.EOF
    7.     RowNum = RowNum + 1
    8.     MSFlexGrid1.TextMatrix(RowNum, 1) = rs!FieldName1
    9.     MSFlexGrid1.TextMatrix(RowNum, 2) = rs!FieldName2
    10.     ' and so on
    11.     rs.MoveNext
    12. Wend
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: show data in flexgrid

    but cant i fill it automatically like i would if i had a bound control with a DataGrid?
    I think in that case you just set the DATASOURCE property of the DataGridto the bound control.... and you have it.
    Last edited by Kanbei; Apr 12th, 2006 at 10:28 AM.

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: show data in flexgrid

    The MSFlexGrid cannot be bound directly to a Recordset, only a data control.

    The MSHFlexGrid can be bound directly to a Recordset.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: show data in flexgrid

    Thanks!!
    I had no idea of that control.

    Do you recommend me to you use it? or does it has anything wrong?
    And how do i bound it to my recordset i declared the way i posted in post#1?

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: show data in flexgrid

    VB Code:
    1. Set rsVar = New ADODB.Recordset
    2. rsVar.Open ObjectName, cnVar, adOpenKeyset, adLockPessimistic, ObjectType
    3. Set MSHFlexGrid1.DataSource = rsVar

    There are some differences between the MSHFlexGrid and the MSFlexGrid but when dealing with typical recordsets they are basically the same.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: show data in flexgrid

    Thanks a lot!!!!!

    All the data shows underlined... how can i choose the format and also the alignment of each column (right, centered or left)?

  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: show data in flexgrid

    All the data shows underlined...
    Not sure what that means.

    To align columns use the ColAlignment property

    MSHFlexGrid1.ColAlignment(1) = flexAlignLeftCenter
    MSHFlexGrid1.ColAlignment(2) = flexAlignRightCenter

    how can i choose the format
    You can't format the data when bound directly to the recordset (unless you do it in your sql statement). After the data is loaded you would need to loop through all the cells and format them accordingly - which would defeat the purpose of the binding.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2006
    Posts
    269

    Re: show data in flexgrid

    oh... i had the "underline" chkbox ticked.

    Thanks for all your help! Really!

    Ill mark this as resolved and create another topic if i have trouble... hope i wont.

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