Results 1 to 12 of 12

Thread: FlexGrid Problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    FlexGrid Problem

    Hello,

    I have this method that accepts sqlcommand (string) and FlexGrid, I want to populate the flexGrid with the result of the sql command, as shown below.

    Problem is, it gives me an error.


    Public Sub FillFlexGrid(ByVal sqlcmd As String, ByVal Flxgrid As VSFlex8U.VSFlexGrid)
    Dim tmpTable As DataTable
    dim rw as integer = 0
    dim cl as integer = 0
    Try
    con.Open()
    Dim dtset As New DataSet
    Dim dtad As SqlDataAdapter = New SqlDataAdapter(sqlcmd, con)
    dtad.Fill(dtset, "tmpTable")
    tmpTable = dtset.Tables("tmpTable")

    For Each row As DataRow In tmpTable.Rows
    For Each col As DataColumn In tmpTable.Columns
    With Flxgrid
    .TextMatrix(rw, cl) = row(col)
    cl += 1
    End With
    rw += 1
    Next
    Next
    Catch ex As SqlException
    MessageBox.Show(ex.Message)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    con.Close()
    End Try
    End Sub



    thanks....

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: FlexGrid Problem

    shouldn't it be:

    vb Code:
    1. For Each row As DataRow In tmpTable.Rows
    2.      For Each col As DataColumn In tmpTable.Columns
    3.           With Flxgrid
    4.               .TextMatrix(rw, cl) = row(col)
    5.               cl += 1
    6.           End With
    7.      Next
    8.      rw += 1
    9.      cl = 0
    10. Next

    what error are you getting?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: FlexGrid Problem

    Private Sub btnShowApplicants_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowApplicants.Click
    Dim db As New CntrlLinkDbase
    Dim sqlcmd As String = " SELECT * from VwApplicant Order by Lastname"

    db.FillFlexGrid(sqlcmd, flxGrids) ' <-- Here is the Error

    End Sub

    =========================================================
    Error Message
    Unable to cast object of type 'AxVSFlex8U.AxVSFlexGrid' to type 'VSFlex8U.VSFlexGrid'.
    =========================================================



    Public Sub FillFlexGrid(ByVal sqlcmd As String, ByVal Flxgrid as VSFlex8U.VSFlexGrid)
    Dim tmpTable As DataTable
    Dim rw As Integer = 0
    Dim cl As Integer = 0
    Try
    con.Open()
    Dim dtset As New DataSet
    Dim dtad As SqlDataAdapter = New SqlDataAdapter(sqlcmd, con)
    dtad.Fill(dtset, "tmpTable")
    tmpTable = dtset.Tables("tmpTable")

    For Each row As DataRow In tmpTable.Rows
    For Each col As DataColumn In tmpTable.Columns
    'FlexAdjustment.TextMatrix(FlexAdjustment.Row, 2)
    With Flxgrid
    .TextMatrix(rw, cl) = row(col) '<---- Error is here when step
    cl += 1
    End With
    rw += 1
    cl = 0
    Next
    Next
    Catch ex As SqlException
    MessageBox.Show(ex.Message)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    con.Close()
    End Try
    End Sub


    thanks

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: FlexGrid Problem

    is there in anyway a style of passing an flexgrid object and sqlcommand (string) to a method then populate that flexgrid?


    thanks

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: FlexGrid Problem

    try
    vb Code:
    1. Public Sub FillFlexGrid(ByVal sqlcmd As String, ByVal Flxgrid as AxVSFlex8U.AxVSFlexGrid)
    2.     'etc

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: FlexGrid Problem

    That's how I did in my Method, see above Method Definition...


    Private Sub btnShowApplicants_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowApplicants.Click
    Dim db As New CntrlLinkDbase
    Dim sqlcmd As String = " SELECT * from VwApplicant Order by Lastname"

    db.FillFlexGrid(sqlcmd, flxGrids) ' <-- Here is the Error Type Cast Error

    End Sub

    =========================================================
    Error Message
    Unable to cast object of type 'AxVSFlex8U.AxVSFlexGrid' to type 'VSFlex8U.VSFlexGrid'.
    =========================================================


    Thanks

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: FlexGrid Problem

    in your method you're using

    vb Code:
    1. ByVal Flxgrid as VSFlex8U.VSFlexGrid

    which should be

    vb Code:
    1. ByVal Flxgrid as AxVSFlex8U.AxVSFlexGrid

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: FlexGrid Problem

    Thanks, Got it...

    by the way, how can I add row and Column at runtime?

    For Each row As DataRow In tmpTable.Rows
    For Each col As DataColumn In tmpTable.Columns
    With Flxgrid
    If IsDBNull(row(col)) Then
    .set_TextMatrix(rw, cl, "")
    Else
    .set_TextMatrix(rw, cl, row(col))
    End If
    cl += 1
    End With
    Next
    cl = 1
    rw += 1
    Next


    thanks .paul

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: FlexGrid Problem

    you have to set the flexgrid .col + .row then read each cell in your table and use the flexgrid.text property to put the values in the flexgrid cells.
    i'm not sure what .set_TextMatrix does, but i don't think you need it.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: FlexGrid Problem

    the .set_TextMatrix(rw, cl, row(col)) put values to a specified cel in the flex,

    the flexgrid.text accepts only string theres no row and column argument.





    For Each row As DataRow In tmpTable.Rows
    For Each col As DataColumn In tmpTable.Columns
    With Flxgrid
    If IsDBNull(row(col)) Then
    .set_TextMatrix(rw, cl, "")
    Else
    .set_TextMatrix(rw, cl, row(col))
    End If
    cl += 1
    .Cols = cl '<--- I try this to add new columns but has error
    End With
    Next
    cl = 1
    rw += 1
    Flxgrid.Rows = rw '<--- Same with this
    Next


    Thanks

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: FlexGrid Problem

    i see the problem now. what you're doing is setting the number of columns in your loop which means cols = 1, cols = 2, cols = 10. then when you get to the new row, cols = 0.

    try this before the loop

    vb Code:
    1. Flxgrid.cols = tmpTable.Columns.count
    2. Flxgrid.rows = tmpTable.Rows.count

    then remove the resizing code from the loop

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    29

    Re: FlexGrid Problem

    @.paul.


    Now it all works fine...


    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
  •  



Click Here to Expand Forum to Full Width