none
Get item from SortedSet in C# RRS feed

  • Question

  • Hi Team,

    I am using SortedSet as like below. And binding this SortedSet as DataSource for my control. Please refer below codes.

     private SortedSet<(DateTime val, string show)> Dates = null;

            public Form1()
            {
                InitializeComponent();
                Dates = new SortedSet<(DateTime val, string show)>();
                DateTime dt;
                dt = DateTime.Parse("01/01/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));
                dt = DateTime.Parse("02/01/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));
                dt = DateTime.Parse("01/15/2019 12:00:00"); Dates.Add((val: dt, show: dt.ToString("D")));

                myControl.DataSource = Dates;

    //Trying to display show from this source.

    myControl.DisplayMember = "show";

            }       

    I am unable to get the show value seperatly in my source. What i need is i need to maintain this sort table and get the "show" members from this source. 

    Please let me know if you need further details.


    R.Senthil


    • Edited by Kumaran619 Friday, September 13, 2019 6:38 AM
    Friday, September 13, 2019 6:38 AM

All replies

  • Hi Kumaran619,

    Maybe you can try to set data source directly like the followed?

        myControl.DataSource = Dates.Select(x => x.show).ToList();

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 13, 2019 8:00 AM
    Moderator
  • Hello,

    From the provided code 

    myControl.DataSource = Dates;

    looks like myControl not initialized.

    There also no code for myControl - not possible to say is there a bug or not.

    It may be easier for you if you create special type t hold DateTime value(val) and string to display (show) - current implementation hide this type from you.


    Sincerely, Highly skilled coding monkey.

    Friday, September 13, 2019 8:13 AM
  • Hi @kyle - Thanks for the workaround. Is there any other solution for this?

    @Andrey - myControl is the customControl created by me. So in my control. I am trying to assign display member and value member from this DataSource. In my control, i could not able to get the data from source using display member and value member, could you please suggest any solution for this?



    R.Senthil

    Friday, September 13, 2019 8:18 AM
  • In my control, i could not able to get the data from source using display member and value member

    -----

    Interesting... as many do before you - you asking about problem in your code... but without providing a code. Which kind of suggestion you expecting in this situation? 

    In my implementation of DataSource (it's basically an object) I have as a sources classes which aggregate (not inherit) a DataTable. But implementation I made do get access to DataTable and use it to fill grids/combos&etc. Your implementation need to known how to work with type created for SortedSet<>. I already suggest to create this class manually - this will allow you to use this type in your control code,


    Sincerely, Highly skilled coding monkey.

    Friday, September 13, 2019 9:41 AM