Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-09-20
4
Medium Priority
?
294 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 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

963 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