We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Get selected entity from list box

Thread ID:

Created:

Updated:

Platform:

Replies:

121420 Dec 11,2015 04:58 PM UTC Dec 18,2015 12:37 PM UTC ASP.NET Web Forms 8
loading
Tags: ListBox
Manolo
Asked On December 11, 2015 04:58 PM UTC

Hi,

I fill a list box with SelectMethod, and when the user click on process, I need the selected Item from ListBox, but I don't know how get this class:

The Items collections are empty, but the items are showed, selectedIndices always return 0, only SelectedItemIndex works, but I don't want the index, I want the entity or the value field.

I've a similar problem with the dropdownlist

Also, the visualization is wrong

I attach a similar project for test

Attachment: WebApplication1_42b5d53a.zip

Manolo
Replied On December 15, 2015 09:09 AM UTC

Any idea?

Kalai Selvi Rajendran [Syncfusion]
Replied On December 15, 2015 01:02 PM UTC

Hi Manolo,

Sorry for the inconvenient.

Since the reported requirement as a defect, we have created an incident in your account. Kindly follow up the incident for further queries.

Please let me know if any concerns.

Regards,

Kalai Selvi


Manolo
Replied On December 15, 2015 01:04 PM UTC

Ok!

Alisasmith
Replied On December 16, 2015 06:56 AM UTC

Hi Monolo,

Use the following code to resolve this issue:-

private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
   // Get the currently selected item in the ListBox.
   string curItem = listBox1.SelectedItem.ToString();

   // Find the string in ListBox2.
   int index = listBox2.FindString(curItem);
   // If the item was not found in ListBox 2 display a message box, otherwise select it in ListBox2.
   if(index == -1)
      MessageBox.Show("Item is not available in ListBox2");
   else
      listBox2.SetSelected(index,true);
}

Helpful resource :-https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.selecteditem%28v=vs.110%29.aspx

Thanks!!
 

Manolo
Replied On December 16, 2015 08:27 AM UTC

this listbox don't have the property SelectedItem.

This is the problem.

And.... what about the visualization?  Why  when I select the second or third items, the text are moved?

Kalpana Kandasamy [Syncfusion]
Replied On December 17, 2015 03:52 PM UTC

Hi Monolo,
We have analyzed your requirement “to get the selectedItems in the listbox” can be achieved by using following code snippet to your application.
 protected void butn_Click(object Sender, Syncfusion.JavaScript.Web.ButtonEventArgs e)

        {

            //to assign the selected items in the listbox controls

            int selectItemIndex = ListBox1.SelectedItemIndex;

            Item selectedItem;;

            if (selectItemIndex == -1)

                selectedItem = null;

            else

              selectedItem = GetItems().ElementAt(selectItemIndex); // to get the element based on our selected index

            //get the text from the selected element if its not means return the message

             var selectedText = selectedItem!=null? selectedItem.Name:"Item is not available in ListBox2";
       }
 

 
And also we have prepared a simple sample to exhibit your requirement, please download from the below downloadable link.
Sample Location: Sample
 If still you have face any difficulties while get the element, please revert back us we will happy to assist you.
Regards,
Kalpana K

Manolo
Replied On December 17, 2015 05:55 PM UTC

Hi,

Thanks for your answer. It's a temporal solution.

But I've other question.... in my example, when I select the second or third item, my visualization is wrong, and in your example it works fine, Why?

Kalpana Kandasamy [Syncfusion]
Replied On December 18, 2015 12:37 PM UTC

Hi Manolo,
After analyzing more about your sample, we have found that the reported issue  “The visualization problem after selecting the second or third item” caused due to the bootstrap CSS used in your application.
In our last update, we have provided sample does not include the bootstrap CSS file.
We have confirmed this as a defect at our end and logged defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents
Please let us know if you need any further assistance.

Regards,
Kalpana K

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;