Use data in an IVCursor to populate DataGridView in VB,NET

Dennis Wallentin xldennis at gmail.com
Sat Jan 8 16:19:29 CST 2011


Beatrix,

Now I have ported the code to VB.NET and I can agree to populate a listbox
via iteration. However, for more records I would like to see that I can use
the following approach:

Dim con As String = "Driver={Valentina ODBC
Driver};IsDatabaseLocal=yes;Database=FirstDB.vdb"
        Dim sql As String = "SELECT FirstName 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")

        Me.GenBox.DataSource = ds.Tables("Person_Table")
        Me.GenBox.ValueMember = "FirstName"
        Me.GenBox.DisplayMember = "FirstName"


In other words, the same solution as for the DataGridView.

Thanks,
Dennis

PS. I took a closer look on Your (?) site and it was interesting to see Your
tool :-)

2011/1/8 Dennis Wallentin <xldennis at gmail.com>

> Beatrix,
>
> Thanks for the input and I will look into it.
>
> Kind regards,
> Dennis
>
> 2011/1/8 Beatrix Willius <bwillius at gmx.de>
>
> 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.
>>
>> _______________________________________________
>> Valentina mailing list
>> Valentina at lists.macserve.net
>> http://lists.macserve.net/mailman/listinfo/valentina
>>
>
>
>
> --
> With kind regards,
> Dennis W
> -------------------------------------------------
> XL-Dennis about .NET & MS Excel
> http://xldennis.wordpress.com/
>
> XL-Dennis Consulting
> http://www.excelkb.com/index.htm
>



-- 
With kind regards,
Dennis W
-------------------------------------------------
XL-Dennis about .NET & MS Excel
http://xldennis.wordpress.com/

XL-Dennis Consulting
http://www.excelkb.com/index.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macserve.net/pipermail/valentina/attachments/20110108/de72653a/attachment.htm>


More information about the Valentina mailing list