2 Replies - 1686 Views - Last Post: 28 November 2012 - 06:37 AM Rate Topic: -----

#1 littledevils326  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-November 12

How to display selected data in Listbox and display in Textbox?

Posted 27 November 2012 - 05:36 PM

I have two forms - one is the main form which has a listbox containing data which is loaded in from a text file. The other is a delivery form. When the user selects an item in the list box and clicks the edit button the delivery form should appear with the selected data displayed in the text box of the delivery form. At the moment I have something like this:

private Visit theVisit = new Visit();
private List<Delivery> deliveries = new List<Delivery>();
private FrmDelivery deliveryForm = new FrmDelivery();

private void updateDelivery()
{
    lstDeliveries.Items.Clear();            
    List<String> listOfD = theVisit.listDeliveries();
    lstDeliveries.Items.AddRange(listOfD.ToArray());            
}

private void btnEditDelivery_Click(object sender, EventArgs e)
{
    deliveryForm.ShowDialog();
    updateDelivery();

}

Is This A Good Question/Topic? 0
  • +

Replies To: How to display selected data in Listbox and display in Textbox?

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5540
  • View blog
  • Posts: 11,868
  • Joined: 02-June 10

Re: How to display selected data in Listbox and display in Textbox?

Posted 27 November 2012 - 05:44 PM

You need to create properties in your second form to send the info into.

From the first form you create an instance of hte second form, then send the info you need. When the form closes you pull the updated info out of it.

Its just like using a OpenFileDialog where you make a dialog, set the InitialDirectory, Filter and so on - show it - then when it is done you retrieve the file path the user selected.
And example of OpenFileDialg use.

The only difference here is that you're creating the dialog instead of using a pre-made one. So you need to create the properties you care about. (Properties tutorial linked in my signature block)

So work this backwards.
First create your EditForm and put in all the properties you need.
Second, from your first form make an instance of the second form and set all the properties as needed.

Give that a shot and post in this thread if you have any trouble and I'll try to nudge you back on track.
Was This Post Helpful? 1
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: How to display selected data in Listbox and display in Textbox?

Posted 28 November 2012 - 06:37 AM

Also, to get the value that was selected, you can use the SelectedItem property of the ListBox.

if (lstDeliveries.SelectedIndex != -1)
{
    string deliveryNumber = lstDeliveries.SelectedItem.ToString();
}


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1