public void select(int z)
{
ListBox1.SelectedIndex = z;
ListBox1.SelectedItem = ListBox1.Items[z];
ListBoxItem
selectedItem=ListBox1.ItemContainerGenerator.ContainerFromItem(this.ListBox1.SelectedItem)
as ListBoxItem;
selectedItem.Focus();
}
In this method I'm trying to select element in the listbox, But the reference variable carrying value is null which is returning by the selec开发者_Python百科tion code.
"ListBox1.ItemContainerGenerator.ContainerFromItem(this.ListBox1.SelectedItem) as ListBoxItem;"
I have debugged my code and keenly observed that the values are coming into the ListBox1 object, but still it is returning a null value.
ListBoxItem selectedItem = ListBox1.ItemContainerGenerator.ContainerFromItem(this.ListBox1.SelectedItem) as ListBoxItem;
TextBox1.Text = selectedItem.Content.ToString();
or is it TextBox1.Context = selectedItem.Content.ToString();
Good luck :)
精彩评论