locked
Find Index of specific value in multidimension Array. RRS feed

  • Question

  • Hallo

    We using a DataGrid to display and select a specific multi dimension objects in a array. I need to find a way to get the index of a selected object based on one element in the list.

    There a collection of single objects to a list. Example below..

    I tried indexof and FindIndex, but the result is -1... So somewhere I missing the point..

    Trying to find the index of a object based on a value, for instance CompanyID 1, index of the list is [0]

    I do get the CompanyID selected correctly, but I would like to find the index of the SingleCompany in the List.


    labjac

    • Changed type Dave PatrickMVP Wednesday, August 19, 2020 6:14 PM question
    • Moved by Naomi N Wednesday, August 19, 2020 7:13 PM Better answer can be here
    Wednesday, August 19, 2020 5:45 PM

All replies

  • I'd try asking for help over here.

    https://docs.microsoft.com/en-us/answers/topics/windows-forms.html

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Wednesday, August 19, 2020 6:15 PM
  • Hallo Dave

    Is this the wrong Forum for the question?


    labjac

    Wednesday, August 19, 2020 7:26 PM
  • Yes, that's correct. The MSDN / TechNet forums are closing.

     

    (please don't forget to mark helpful replies as answer)

     

      



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.


    Wednesday, August 19, 2020 7:28 PM
  • Can you please share your code?

    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

    Wednesday, August 19, 2020 9:26 PM
  • Hi labjac,

    Thank you for posting here.

    FindIndex can work for me, how are you using it? Please show some details.

        class Program
        {
            static void Main(string[] args)
            {
                List<CustomerSingleModel> models = GetModels();
                Console.WriteLine(models.FindIndex(model => model.CompanyID == 2));
                Console.ReadLine();
            }
    
            static List<CustomerSingleModel> GetModels() 
            {
                List<CustomerSingleModel> models = new List<CustomerSingleModel>();
                models.Add(new CustomerSingleModel() { CompanyID = 1, CompanyName = "company1" });
                models.Add(new CustomerSingleModel() { CompanyID = 2, CompanyName = "company2" });
                models.Add(new CustomerSingleModel() { CompanyID = 3, CompanyName = "company3" });
                models.Add(new CustomerSingleModel() { CompanyID = 4, CompanyName = "company4" });
                return models;
            }
        }
        class CustomerSingleModel
        {
            public int CompanyID { get; set; }
            public string CompanyName { get; set; }
        }

    Best Regards,

    Timon


    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.

    Thursday, August 20, 2020 2:55 AM
  • hey. it's ok but it's not really updated. 
    Thursday, August 20, 2020 6:18 AM
  • unfortunatlly yes.
    Thursday, August 20, 2020 6:18 AM