Results 1 to 3 of 3

Thread: Database filtering

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    138

    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?

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Database filtering

    Quote Originally Posted by hepeci View Post
    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.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Database filtering

    Quote Originally Posted by kevininstructor View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width