Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Datatable as DataSource

  1. #1

    Thread Starter
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Resolved [RESOLVED] [2005] Datatable as DataSource

    Hi All,
    I have a data table which has 4 columns. I want to display 1 column and other columns should be invisible. I want to display this column value in a combo box and I've set its properties as follows.

    VB Code:
    1. cbo.datasource=dt
    2. cbo.displaymember= dt.columns(1).Tostring
    3. cbo.ValueMember= dt.columns(0).Tostring
    Is there any way to add the other columns to a collection, hashtable or something directly. (I.e. not one by one, just setting the datasource)


    Any idea will be highly appreciated.
    Thanks
    If the post is heplful, Please Rate it
    Chathura Wijekoon

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

    Re: [2005] Datatable as DataSource

    When the user makes a selection the Selecteditem will return a DataRowView. You can simply index that object to get the other column values, e.g.
    vb.net Code:
    1. Dim val As Object = DirectCast(myComboBox.SelectedItem, DataRowView)("ColumnName")
    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

  3. #3

    Thread Starter
    Hyperactive Member Chathura's Avatar
    Join Date
    Nov 2005
    Location
    Sri Lanka
    Posts
    345

    Re: [2005] Datatable as DataSource

    Great!!!!
    Mr. John

    Thank you very much.

    It's working perfectly
    If the post is heplful, Please Rate it
    Chathura Wijekoon

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