|
-
Dec 23rd, 2009, 08:15 AM
#1
Thread Starter
Addicted Member
Database filtering
Hello everybody!
I'm using one Access Database and DataSet, BindingSource And Table Adapter. My question is: how to fill one listbox on my form with dates from one row from Database.
Look at the picture:
http://www.imagesforme.com/show.php/870175_table.JPG
So listbox needs to have 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20.
How to to this, code?
-
Dec 23rd, 2009, 08:57 AM
#2
Re: Database filtering
 Originally Posted by hepeci
Hello everybody!
I'm using one Access Database and DataSet, BindingSource And Table Adapter. My question is: how to fill one listbox on my form with dates from one row from Database.
Look at the picture:
http://www.imagesforme.com/show.php/870175_table.JPG
So listbox needs to have 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20.
How to to this, code?
I suggest learning the basics at this point. Here are some ideas...
Set your DisplayMember to the field to view (assume a date), ValueMemer is the ID (assume from your image). Then set the data source of the ListBox to the BindingSource. Double click the ListBox, in the selection change event write code to retreive the ID, something like
ListBox1.Text gives you the date
ListBox.SelectedValue gives the ID
You could simply populate the Listbox with the Binding source, create an onchange event for the Binding source, get the current position and then get the ID.
Declare bindingsource
Code:
Private WithEvents bsSource As New BindingSource()
Declare a private var for holding the ID
Code:
Private mIdentifier As String
Write code to get the ID
Code:
Private Sub bsSource_PositionChanged() Handles bsSource.PositionChanged
If Not IsNothing(bsSource.Current) Then
mIdentifier = CType(bsSource.Current, DataRowView).Item("Identifier").ToString()
End If
End Sub
In the above code my source id a DataView, if you are using a DataTable then change the casting.
Hope this helps.
-
Dec 23rd, 2009, 05:41 PM
#3
Re: Database filtering
 Originally Posted by kevininstructor
In the above code my source id a DataView, if you are using a DataTable then change the casting.
When you bind a DataTable the items are still DataRowView objects because they come from the table's DefaultView. That's why it's generally pointless to bind a DataView directly. The only reason to do that is if you want multiple views of the same table.
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
|