Hi, in my case, after loading ExcelData, I move the item(s) around to other listboxes depends on the type.
So let me rephrase my question,
below is my listbox
<ListBox x:Name="lslSubjAcct" />
Because I wrote codes to load data to lstSubjAcct listbox in a button click event therefore I have no ItemsSource binding in my xaml file.
Now I need to get all items in my lstSubjAcct listbox to a string in the viewmodel, how do I do that ? Thank you!
private void BtnAddSubject_Click(object sender, RoutedEventArgs e)
{
string currentItemText;
int currentItemIndex;
List<string> myDataList = new List<string>();
foreach (object item in lstAllAcct.Items)
myDataList.Add(item as string);
// Find the right item and it's value and index
currentItemText = lstAllAcct.SelectedValue.ToString();
currentItemIndex = lstAllAcct.SelectedIndex;
lslSubjAcct.Items.Add(currentItemText);
if (myDataList != null)
{
myDataList.RemoveAt(currentItemIndex);
}
// Refresh data binding
ApplyDataBinding(myDataList);
}
private void ApplyDataBinding(List<string> myNewDataList)
{
lstAllAcct.ItemsSource = null;
// Bind ArrayList with the ListBox
lstAllAcct.ItemsSource = myNewDataList;
}