|
-
Jan 23rd, 2008, 07:09 AM
#1
Thread Starter
Junior Member
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....
-
Jan 23rd, 2008, 07:15 AM
#2
Re: FlexGrid Problem
shouldn't it be:
vb Code:
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
Next
rw += 1
cl = 0
Next
what error are you getting?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 23rd, 2008, 07:43 AM
#3
Thread Starter
Junior Member
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
-
Jan 23rd, 2008, 07:50 AM
#4
Thread Starter
Junior Member
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
-
Jan 23rd, 2008, 08:02 AM
#5
Re: FlexGrid Problem
try
vb Code:
Public Sub FillFlexGrid(ByVal sqlcmd As String, ByVal Flxgrid as AxVSFlex8U.AxVSFlexGrid)
'etc
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 23rd, 2008, 08:08 AM
#6
Thread Starter
Junior Member
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
-
Jan 23rd, 2008, 08:14 AM
#7
Re: FlexGrid Problem
in your method you're using
vb Code:
ByVal Flxgrid as VSFlex8U.VSFlexGrid
which should be
vb Code:
ByVal Flxgrid as AxVSFlex8U.AxVSFlexGrid
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 23rd, 2008, 08:37 AM
#8
Thread Starter
Junior Member
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
-
Jan 23rd, 2008, 08:48 AM
#9
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.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 23rd, 2008, 09:01 AM
#10
Thread Starter
Junior Member
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
-
Jan 23rd, 2008, 09:17 AM
#11
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:
Flxgrid.cols = tmpTable.Columns.count
Flxgrid.rows = tmpTable.Rows.count
then remove the resizing code from the loop
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 23rd, 2008, 09:53 AM
#12
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|