Sorry simple newbie question - saving data

Hi there, sorry to appear dim but i've not done a lot of programing and i am basically teaching myself from books.

I have a form in which i'm displaying the text property of the controls on the form in a list box. You can then select one of these from the list box and display it in a text box.
You can then modify the controls text property to something of your own choice, in the textbox.

This i have managed to do successfully.

What i can't manage to do is save the results. Once you have made the changes you click on the "save changes" button. What code should i put in here to save the new controls text property and display it in the list box 

I think i've done the hardest part - just can't figure out the simple stuff (Doh !)

TIA


Answer this question

Sorry simple newbie question - saving data

  • Sasco

    Kinda sounds like you are going about it wrong.

    There a few things you can have:

    1) List Box - Lists strings.

    2) Drop Down List box - Same as a list box but only shows one at a time and has the user click a button to drop down the full list.

    3) Combo List box - This is like a Drop Down list box except that the items can be editable.


    I'm not sure why you have a list box and a text box when it sounds like it would be more appropriate to use a Combo List box since the user can just edit the items directly in the combo box.

  • Greg Thomas

    Override the Click event of the button.


    protected void OnClick(object sender, EventArgs e)
    {
       //Get the selected index of the list box. Returns -1 if nothing is selected.
       // See the MSDN Documentation on ListBox Class Members.
       int nIndex = this.m_ListBox.SelectedIndex;

       if(nIndex != -1)
       {
             //Using the selected index, reset the value of the selected
             //list box item using the value in the text box.
             this.m_ListBox.Items[nIndex] = this.m_TextBox.Text;
        }
    }


    Would that work for you  Maybe I don't understand your problem.
    That code would update the selected list box string from the contents of a text box when a button is pushed.

  • Dan Fisherman

    Hiya,

    "Kinda sounds like you are going about it wrong" - Most probably !!

    This is my first programming project and I'm helping to re-style a software program we currently have. I'm copying the functionality of a particular form within this program. This is just how i see how the current form has been set up at present.

    I did consider using a combo box, but would whatever was selected disappear as soon as you started typing   I think they choose a listbox and text box, so customers can see what they have selected in one area and type the changes in another. So if they start typing and forget what it is they are about to change, they can see what they selected in the list box.

    If i continue to use the listbox, i realise that i need to be able to say for e.g. that item number 6 was choosen, so when you've finished typing and i press save, item number 6 needs updating in the list box.
    I just can't seem to get this to work in my sample. Please don't ask me to put this code up here for scrutiny, as i'm just too embarrased as to how pants it will probably look !




  • Sorry simple newbie question - saving data