Originally, i am dealing with multiple column of listbox, however listbox do not have multiple column
then i change to use listview
<ListView Name="listboxListBox1" DataContext="{Binding Stock}" Grid.Column="1" Height="100" Width="280" Margin="6" HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Visible"><ListView.View><GridView><GridViewColumn Header="Name" Width="100"><GridViewColumn.CellTemplate><DataTemplate><TextBlock Name="Name" Text="{Binding Path=Name}" /></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn><GridViewColumn Header="Value" Width="100"><GridViewColumn.CellTemplate><DataTemplate><TextBlock Name="Value2" Text="{Binding Path=Value2}" /></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn></GridView></ListView.View></ListView></Grid> public class Stock : INotifyPropertyChanged { private string name; private string value2; public Stock() { } public string Name { get { return name; } set { if (Name != value) { name = value; OnPropertyChanged("Name"); } } } public string Value2 { get { return value2; } set { if (Value2 != value) { value2 = value; OnPropertyChanged("Value2"); } } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(String info) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(info)); } } } public partial class ListBoxOfItemsControl : AbstractControlClass { public ObservableCollection<Stock> Stock { get; set; } public ListBoxOfItemsControl instance; public ListBoxOfItemsControl() { InitializeComponent(); listboxListBox1.SelectionMode = SelectionMode.Multiple; if (Stock == null) Stock = new ObservableCollection<Stock>(); DataContext = this; } public ListBoxOfItemsControl getInstance() { if (instance == null) instance = new ListBoxOfItemsControl(); return instance; } public override void InitializeControls(int i, Control o, DataTable dt) { ListBoxOfItemsControl oo = (ListBoxOfItemsControl)o; oo.Name = dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.Name].ToString().Trim(); oo.listboxlabel1.Content = dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.LabelText].ToString().Trim(); List<String> selecteditems = new List<String>(); DataTable extensiondt = DataAccessLayer.getTable("ReportUIExtension", "", selecteditems, "E01"); List<String> DBF_FUNDselecteditems = new List<String>(); DBF_FUNDselecteditems.Add(dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.ListBoxKeyColumnName].ToString().Trim()); DBF_FUNDselecteditems.Add(dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.ListBoxValueColumnName].ToString().Trim()); DataTable DBF_FUND = DataAccessLayer.getTable(dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.ControlTableName].ToString().Trim(), "", DBF_FUNDselecteditems, ""); for (int j = 0; j < DBF_FUND.Rows.Count; ++j) { Stock s = new Stock(); s.Name = DBF_FUND.Rows[j].ItemArray[0].ToString().Trim(); s.Value2 = DBF_FUND.Rows[j].ItemArray[1].ToString().Trim(); Stock.Add(s); } } public override void InitializeaddValuesToReportParameter(ref ReportCriteria rc, Hashtable controlHashTable, int i, Control o, DataTable dt) { ListBox listboxobj = ((ListBoxOfItemsControl)controlHashTable[dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.Name].ToString().Trim()]).listboxListBox1; List<String> multipleValueResult = new List<String>(); for (int k = 0; k < listboxobj.SelectedItems.Count; ++k) { multipleValueResult.Add(listboxobj.SelectedItems[k].ToString()); } if (multipleValueResult != null) rc.AddEntry(dt.Rows[i].ItemArray[(int)ItemsControlFactory.ReportUIColumn.ItemType1].ToString().Trim(), multipleValueResult, "xs:string"); } public override String GetValue() { String result = ""; for (int i = 0; i < listboxListBox1.SelectedItems.Count; ++i) { if(String.IsNullOrEmpty(result)) result = listboxListBox1.SelectedItems[i].ToString(); else result = result+ "," + listboxListBox1.SelectedItems[i].ToString(); } return result; } }
No need to worry as many books are not the core and true story