Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Save value from the combobox for the index that will be changed.

For e.g: If I have 5 items listed and 1st one is selected and when I change index to suppose 4th one, I need to save the value of 1st listed item at time of index being changed and next time if I select 2nd item on the list it needs to save value for 4th one at time of index change.

I need to pass that value for batch name in the below listed stored procedure every time index is changed so that previous selected index can be unlocked.

cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_CAMR_UnlockedBatchName";
cmd.Parameters.AddWithValue("@Batch_Name", temp);
cmd.Parameters.AddWithValue("@lst_mod_userid", Environment.UserName);
Posted
Comments
Gokulprasad05 3-Feb-16 23:31pm    
You aim is single class and multiple specification. Correct or not?

Why not use a 'Stack to save a certain number of the previous ComboBox selections ? This is a class I use to implement a fixed-size Stack of any Type:
C#
using System.Collections.Generic;

namespace StackAndQueueUtilityClasses
{
    public class StackT<T> : Stack<T>
    {
        private int Capacity { set; get; }

        private Stack<T> tempStack;
 
        public StackT(int capacity)
        {
            Capacity = capacity;
            tempStack = new Stack<T>(Capacity);
        }

        public T GetLastValueIn()
        {
            return base.Peek();
        }

        // disable use of 'Pop
        public new T Pop()
        {
            return default(T);
        }

        public new void Push(T value)
        {
            if (this.Count == Capacity)
            {
                tempStack.Clear();
                
                for (int i = 1; i < Capacity; i++)
                {
                   tempStack.Push(base.Pop());
                }

                base.Clear();

                for (int i = 1; i < Capacity; i++)
                {
                    base.Push(tempStack.Pop());
                }
            }

            base.Push(value);
        }
    }
}
So, if I want a stack of 'ints whose size is limited to #8:

StackT<int> testStack = new StackT<int>(8);

Note that here I have disabled access to 'Pop from outside any instance of the Class, and defined a Method 'GetLastValueIn to return the value at the top of the stack without removing it.

However, you could still call 'Clear to reset this 'Stack overload.

Also note that 'Capacity can only be set in the 'ctor of the Class.

If you want to access some value at a specific position in the Stack without removing the current entries ... you can write code to do that using the same techniques shown here.

There are other data structures you could explore for this: just search CodeProject on Queue, Stack, Circular Buffer.
 
Share this answer
 
v2
Comments
Maciej Los 22-Feb-16 5:25am    
5ed!
SelectedIndexChanged event of combobox is unable to help you as if you try to get the SelectedText value in a SelectedIndexChanged or SelectedValueChanged event handler, the property returns an empty string. This is because, at the time of these events, the previous SelectedText value has been cleared and the new value has not yet been set. To retrieve the current value in a SelectedIndexChanged or SelectedValueChanged event handler, use the SelectedItem property instead.
The good way is, after selecting value in comboxbox, set selected text to some Global variable and refresh it after every selectedIndex change.
 
Share this answer
 
On SelectedIndexChanged you can write your Stored Proc code and send the data to database everytime the SelectedIndexChanges.
Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900