SelectedItem ?

8 posts, 0 answers
  1. Louis
    Louis  avatar
    44 posts
    Member since:
    Sep 2007

    Posted 02 Oct 2007 Link to this post

    How do you get the underlying item bound in a combobox ?

    i set like this 

    cbbTO.DataSource = GetMyObjList();

    cbbTO.ValueMember = "Id";

    and when i want to get the selected one

    cbbTO. SelectedItem as MyObj;

    returns null?

    How can i get the selected databound Item?

    thanks

  2. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 04 Oct 2007 Link to this post

    Hello Louis ,

    Initially, when a data source is assigned to RadComboBox.DataSource property, there is no selected item. Then you can use SelectedIndex or SelectedItem properties to select an item. If you want to use SelectedValue property you should set a priori ValueMember property to the corresponding data field. If there is no selected item, the SelectedItem would return null. 

    Please check your implementation meets the necessary conditions. If it seems to be ok, please try to reproduce the problem in a small sample application and send it to us so we can examine it and find where is the problem.


    Kind regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Paul Yerre
    Paul Yerre avatar
    7 posts
    Member since:
    Mar 2006

    Posted 25 Oct 2007 Link to this post

    I am having the same issue...i have tried to get the bound data item  by using

    carentity1 = ctype(radcombo.selecteditem,carentity)

    this does not work. 
  5. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 29 Oct 2007 Link to this post

    Hello Paul Yerre,

    Most likely this is because the cast of the value returned by SelectedItem property does not succeed. Regardless of the type of this property (for example, an object), it returns an instance of the RadComboBoxItem, which is currently selected. If no item is currently selected, this property returns a value of null.

    Please, don't hesitate to write us if you need any additional assistance.

    Regards,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Paul Yerre
    Paul Yerre avatar
    7 posts
    Member since:
    Mar 2006

    Posted 29 Oct 2007 Link to this post

    so is it possible to get the object?
  7. Georgi
    Admin
    Georgi avatar
    212 posts

    Posted 30 Oct 2007 Link to this post

    Hello Paul Yerre,

    Yes, it is possible to do that using the ItemDataBound event. You could use the DataBoundItem property of the arguments to obtain RadComboBox item and the DataItem property to obtain the corresponding data object.

    Then, you could assign the value of the DataItem to the RadComboBoxItem.Tag property and use the reference later. A different way is to obtain the corresponding data object through the current position on the binding source. However, this is possible only if the combobox control is bound to an IBindingList source.

    Thank you for writing. Contact us again if you have any other questions.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Mel Grubb
    Mel Grubb avatar
    4 posts
    Member since:
    Mar 2009

    Posted 23 Mar 2009 Link to this post

    I have to chime in and say that in my opinion, if the ValueMember has not been set to anything, then by default the SelectedValue property should return the original bound object.  Having to manually copy the object to the item's Tag event is far from the expected behavior.  The base windows controls do this, so I would think that the Rad controls, being a supposed improvement, would have at least the same capabilities.  Certainly if the code to take the bound object and copy a reference off into the tag property can be represented in 5-6 lines of code, then a similar 5-6 lines of code which provide the normally expected behavior should find their way into the next release.

    C'mon, copying the value into the tag? Are you serious? Make the control work the way its expected to out of the box. At a minimum, the controls should do what the built-in WinForm controls do. All the themeing support in the world won't make developers more productive if core functionality requires a series of manual workarounds.
  9. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 26 Mar 2009 Link to this post

    Hello Mel Grubb,

    Thank you for constructive feedback - we do appreciate it. We completely agree with you that, at the very minimum, we should support the same features as the standard toolbox controls. We do our best to address this shortcoming as soon as possible (Q1 SP2, or Q2 2009).
     
    Please write back if you have more suggestions, questions or would like to point out other gaps that you have spotted in our controls.
     

    Greetings,
    Victor
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Back to Top
UI for WinForms is Visual Studio 2017 Ready