1 Attachment(s)
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
Re: Solve Listbox Problem
Quote:
Edit: Added tags for clarity. - Hack
...Didn't help. I'm still confused.
Re: Screen Pictur is Attached
lstSelectedBen.Items.Add(lstAvailBen.SelectedItem.ToString());
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.