Easy_Rider9999 Posted February 13, 2009 Posted February 13, 2009 I want to set the DataSource Property of a listview and of a combobox to an array of datarows. This is the 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 Quote
Administrators PlausiblyDamp Posted February 14, 2009 Administrators Posted February 14, 2009 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Easy_Rider9999 Posted February 14, 2009 Author Posted February 14, 2009 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 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...... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.