Solved

How to get an element in the ListBox and put it in textbox

Posted on 2011-09-20
4
248 Views
Last Modified: 2013-12-17
Hi,
I have a little problem I want to get the code for the selected item in the listbox, but only the code and add it to my textbox. my code below show what I want
Any idea?
Apparently it's easy to get all the SelectedItem but I want only part I have already put in an ArrayList m_currentLookupCodeChoice

thank you in advance
private void lbxListeEvent_SelectedIndexChanged(object sender, EventArgs e)
        {

            if (lbxListeEvent.Items != null)

                tbCode.Text += m_currentLookupCodeChoice+ ".";
            
        }

        /// <summary>
        /// Getting ParseBet response asynchrounsly 
        /// </summary>
        /// <param name="asynchronousResult"></param>
        public void ParseBetResp_Callback(IAsyncResult asynchronousResult)
        {

            string myResponse = null;
            try
            {
                myResponse = isbb.RetailServices.HttpGetResponse(asynchronousResult);
                Debug.WriteLine("ParseBet Response : " + myResponse);
            }
            catch (WebException)
            {
            }
            if (myResponse != null)
            {
                Invoke(new MethodInvoker(delegate
                 {
                     DisplayResponse(myResponse);
                 }
                    ));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="asynchronousResult"></param>
        private void DisplayResponse(string myResponse)
        {
            MyObject myObject = null;

            myObject = isbb.RetailServices.ReadToObjectMyObject(myResponse);
            if (myObject != null)
            {
                if (myObject.mySelection == null)
                {
                    tbBetDescription.Text = myObject.currentSelectionDescription;
                    lbxListeEvent.Items.Clear();
                  
                    foreach (var item in myObject.choices)
                    {
                        lbxListeEvent.Items.Add(item.Code + "  :  " + item.description);
                        m_currentCodeChoice.Add(item.Code);
                       
                    }
                     
                   
                }

                else if (myObject.choices.Count == 0)
                {
                    tbBetDescription.Clear();
                    lbxListeEvent.Items.Clear();

                    lbxCapture.Items.Add(myObject.mySelection.eventLookupCode + ". " + myObject.mySelection.description);
                    lbxCapture.Items.Add(isbb.NetworkServices.ConvertDate(myObject.mySelection.eventStartDate));
                    lbxCapture.Items.Add(myObject.mySelection.marketDescription + "   " + myObject.mySelection.periodDescription);
                    lbxCapture.Items.Add(myObject.mySelection.outcomeDescription + "   " + myObject.mySelection.price);
                    lbxCapture.Items.Add("");
                    tbCode.Clear();
                    m_reponse.Add(myObject.mySelection.lookupCode);

                    btnSubmit.Enabled = true;
                    btnClearCapture.Enabled = true;
                    m_nbreOfBet = m_reponse.Count.ToString();

                    lblNbreOfElt.Text = m_nbreOfBet;
                    m_currentCodeChoice.Clear();

                    
                }
            }

        }

Open in new window

0
Comment
Question by:abgconsulting
  • 2
  • 2
4 Comments
 

Author Comment

by:abgconsulting
ID: 36569556
Do you have any idea ????
0
 
LVL 8

Accepted Solution

by:
jagrut_patel earned 500 total points
ID: 36571848
Not sure what are asking for!

I didn't get what you mean by "but I want only part I have already put in an ArrayList m_currentLookupCodeChoice". Your code does not show where "m_currentLookupCodeChoice" is populated.
In your code there is a line "m_currentCodeChoice.Add(item.Code);". A different variable name! Assuming it is a typo I think you need this,


string code;
foreach (string selectedItem in lbxListeEvent.SelectedItems)
{
    code = selectedItem.Substring(0, selectedItem.IndexOf(':') + 1).Trim();
    foreach (string lookupCode in m_currentLookupCodeChoice)
    {
        if(lookupCode.Equals(code, StringComparison.CurrentCultureIgnoreCase))
            tbCode.Text += code + ".";
    }
}

Open in new window


HTH!
0
 

Author Comment

by:abgconsulting
ID: 36573519
thanks Jagrut !!! u put me on the way to solve my problem !!!


Moussa
0
 
LVL 8

Expert Comment

by:jagrut_patel
ID: 36573747
Please don't forget to rate the solution.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Article by: Nadia
Linear search (searching each index in an array one by one) works almost everywhere but it is not optimal in many cases. Let's assume, we have a book which has 42949672960 pages. We also have a table of contents. Now we want to read the content on p…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now