开发者

Get selected item value from listbox

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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜