Solved

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

Posted on 2011-09-20
4
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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