Use data in an IVCursor to populate DataGridView in VB,NET
Beatrix Willius
bwillius at gmx.de
Sat Jan 8 08:39:49 CST 2011
For a normal listbox you need to loop through the cursor and add a row for each record. With a few 1.000 rows this is pretty slow. For Realbasic there is a control called DataGrid, which loads only the visible rows. I'm sure there will be something similar for .Net.
Code from Listbox:
Private Sub AddRowsOfListbox(theCursor as VCursor)
dim theCol as integer
dim FieldCount as Integer = theCursor.FieldCount
dim ValentinaString as new HandleValentinaString
Do
Me.addrow "" '<------ row added here
theCol = 0
dim RowIDInformation as new Dictionary
For currentField as Integer = 1 to FieldCount
if InStr(theCursor.Field(currentField).Name, "ID") = 0 then
Me.cell(Me.lastIndex, theCol) = ValentinaString.GetString(theCursor.Field(currentField)) '<---- add data to cells
theCol = theCol + 1
else
RowIDInformation.Value(theCursor.Field(currentField).Name) = theCursor.Field(currentField).GetString
end if
next
me.RowTag(me.LastIndex) = RowIDInformation
loop until not theCursor.NextRecord
End Sub
Code from RequestRowData in DataGrid:
Sub RequestRowData(RowNumber as Integer,Row as DataGridRow) '<--- no cursor here, just the row number
me.LockDrawing = true
dim theCol as integer = 1
dim FieldCount as Integer = DataCursor.FieldCount
dim ValentinaString as new HandleValentinaString
dim RowIDInformation as new Dictionary
DataCursor.Position = RowNumber '<--- set position of cursor
For currentField as Integer = 1 to FieldCount
if InStr(DataCursor.Field(currentField).Name, "ID") = 0 then
Row.CellText(theCol) = ValentinaString.GetString(DataCursor.Field(currentField))
theCol = theCol + 1
else
RowIDInformation.Value(DataCursor.Field(currentField).Name) = DataCursor.Field(currentField).GetString
end if
next
Row.ItemData = RowIDInformation
me.LockDrawing = false
End Sub
HTH
On 08.01.2011, at 15:27, Dennis Wallentin wrote:
> Thanks for the valuable input which is appreciated. No, I didn't find among the examples what I'm asking about.
>
> However, as usual ODBC comes to rescure but I still want to use .NET features to do it. The below code shows what I like to achieve:
>
> Dim con As String = "Driver={Valentina ODBC Driver};IsDatabaseLocal=yes;Database=FirstDB.vdb"
> Dim sql As String = "SELECT * FROM Person"
> Dim connection As New OdbcConnection(con)
> Dim dataadapter As New OdbcDataAdapter(sql, connection)
> Dim ds As New DataSet()
> dataadapter.Fill(ds, "Person_Table")
>
> 'Populate the DataGridView with data.
> Me.dgwVDB.DataSource = ds
> Me.dgwVDB.DataMember = "Person_Table"
>
> How can I do it with Valentina's .NET Features?
Mit freundlichen Grüßen/Regards
Trixi Willius
http://www.mothsoftware.com
Mail Archiver X: archive, clean and search email
http://www.beatrixwillius.de
Fractals, 3d landscapes etc.
More information about the Valentina
mailing list