Array of DataRows as DataSource

Easy_Rider9999

New member
Joined
Feb 13, 2009
Messages
2
I want to set the DataSource Property of a listview and of a combobox to an array of datarows.

This is the Code:
Code:
Private Sub fillCBKoerperTeile() (ByVal FilterExpression As String, ByVal Sort As String)
    
    Dim rows() As Data.DataRow
    Dim dr As Data.DataRow

    Try
      rows = dtKoerperTeile.Select(FilterExpression, Sort)
      cbKoerperTeile.DataSource = rows
      cbKoerperTeile.ValueMember = "Name"
      cbKoerperTeile.DisplayMember = cbKoerperTeile.ValueMember
      
    Catch e As Exception
      Throw New ApplicationException(CodeLoc & " Error!", e)
    Finally
      dr = Nothing
    End Try

  End Sub

The Name column does exist but the ComboBox shows only the type of each datarow not the contents! If I set the datasource to a datatable, the correct column is shown in the combobox/listview.

Many Greetings

Hans
 
Would it not be easier to either use the tables DefaultView property or create a new DataView over the table and bind to that rather than creating an array of datarows?
 
Thanks for the reply. I just wanted to post this solution. I found it in a book called Visual Basic.Net. But there is still a problem. If I want to search for a value in a Dataview, I must set the dataview.sort property to the column name. But if I do so the listview is no more sorted the way I want it to be sorted. And if I set .Sort back to the previous value the selection I made before with the .Find Method is lost.




Regards

Hans

Code:
        rows = dtSymptome.Select("Text like " & MakeFitForQuery(txtSymptom.Text) & "*")
        If UBound(rows) < 0 Then
          rows = dtSymptome.Select("Text like *" & MakeFitForQuery(txtSymptom.Text) & "*")
        End If
        mDontUpdateText = True
        Dim oldSort As String = dvSymptome.Sort
        dvSymptome.Sort = "ID"
        For Each row In rows

          SymptomID = row!ID

          find = dvSymptome.Find(SymptomID)
          find = findLstIndex(SymptomID)
          If find >= 0 Then lstSymptome.SetSelected(find, True)
        Next row
        dvSymptome.Sort = oldSort
        mDontUpdateText = False

if I write my own procedure to find the value it is way to slow......
 
Back
Top