Results 1 to 4 of 4

Thread: Screen Pictur is Attached

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    141

    Angry Screen Pictur is Attached

    Code:
    public bool PopList(ListBox cbo ,DataSet ds, int Datasets_Table_Index, string _DisplayMember,string _ValueMember)
    {
    try
    {
    	List.DataSource = ds.Tables[Datasets_Table_Index];
    	List.DisplayMember = _DisplayMember;
    	List.ValueMember = _ValueMember;
    return true;
    }
    catch(Exception e)
    {
    MessageBox.Show(e.ToString());
    return false;
    }		
    }
    we have two listbox
    one listbox fill from database use that function
    when we select item from first listbox and add Second listbox

    use this
    lstSelectedBen.Items.Add(lstAvailBen.SelectedItem);
    system show messsage
    System.Data.DataRow
    nothng list item

    Plzzzzz help me





    Edit: Added [code][/code] tags for clarity. - Hack
    Attached Images Attached Images  
    Last edited by Waseemalisyed; Jan 2nd, 2006 at 11:57 PM.

  2. #2
    New Member
    Join Date
    Dec 2005
    Location
    Anchorage, Alaska
    Posts
    2

    Re: Solve Listbox Problem

    Edit: Added tags for clarity. - Hack
    ...Didn't help. I'm still confused.
    1 3/-\7 n00b5 |=0|2 1|_|/\/{# - pwn
    Social Engineering Specialist--because there is no patch for human stupidity.
    CARPE NOCTEM - yeeeahh baab1e! - The Jargon File ©wr1te

  3. #3
    Hyperactive Member wordracr's Avatar
    Join Date
    Aug 2001
    Posts
    281

    Re: Screen Pictur is Attached

    lstSelectedBen.Items.Add(lstAvailBen.SelectedItem.ToString());

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

    Re: Screen Pictur is Attached

    Quote Originally Posted by wordracr
    lstSelectedBen.Items.Add(lstAvailBen.SelectedItem.ToString());
    That won't work. You have bound the first ListBox to a DataTable so each item is a DataRowView. You can't just add a DataRowView to another ListBox, and calling ToString on it will just return "System.Data.DataRowView". What you want is:
    Code:
    lstSelectedBen.Items.Add(lstAvailBen.GetItemText(lstAvailBen.SelectedItem))
    which will actually get the text displayed in the control for that item. When getting the actual string displayed for an item in a ListBox or ComboBox you should make a habit of ALWAYS using GetItemText. That way you can never go wrong, regardless of what type of objects the ListControl contains.
    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