listBox
-
Hi - I am trying to get my application to automatically select the item that was last added to my list box but am not sure how to get this done. My code so far is as below. Please bear in mind that I am using Windows Presentation Foundation. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); string fileName = dlg.FileName; lstBxList.Items.Add(fileName); //Once the file has been loaded, select it... ???????? }
-
Hi - I am trying to get my application to automatically select the item that was last added to my list box but am not sure how to get this done. My code so far is as below. Please bear in mind that I am using Windows Presentation Foundation. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); string fileName = dlg.FileName; lstBxList.Items.Add(fileName); //Once the file has been loaded, select it... ???????? }
-
Hi - I am trying to get my application to automatically select the item that was last added to my list box but am not sure how to get this done. My code so far is as below. Please bear in mind that I am using Windows Presentation Foundation. private void btnLoad_Click(object sender, RoutedEventArgs e) { //Declare an instance of the open file dialog... OpenFileDialog dlg = new OpenFileDialog(); dlg.ShowDialog(); string fileName = dlg.FileName; lstBxList.Items.Add(fileName); //Once the file has been loaded, select it... ???????? }
Try this
private void button1_Click(object sender, EventArgs e)
{
//Declare an instance of the open file dialog...
OpenFileDialog dlg = new OpenFileDialog();dlg.ShowDialog(); string fileName = dlg.FileName; lstBxList.Items.Add(fileName); lstBxList.SelectedIndex = -1; lstBxList.SelectedIndex = lstBxList.Items.Count - 1; }