none
Data structure for TabControl RRS feed

  • Question

  • I try to use data structure to load data so I can read data one by one TabItem.

    My TabControl contain  lots of TabItems and TabItems contain Canvas

    I Will add images on Canvas on TabItems for example

    Is there any data structure can fulfill my need?

    I can call like dictionary give its key to check its data

    It can enter like hash table I don't need arrange some much space for two dimension array

    Thanks

     


    • Edited by CY_Chen Wednesday, September 18, 2019 5:45 AM
    Monday, September 16, 2019 8:29 AM

Answers

  • Hi,
    I didn't unterstand your problem. Try the following console demo and describe your problem.

    using System;
    using System.Collections.Generic;
    
    namespace ConsoleApp1
    {
      class Program1
      {
        [STAThread]
        static void Main(string[] args)
        {
          try
          {
            (new Demo()).Execute();
          }
          catch (Exception ex) { Console.WriteLine(ex.ToString()); }
          Console.WriteLine("Continue enter key");
          Console.ReadKey();
        }
    
        internal class Demo
        {
          internal void Execute()
          {
            TabItemList tabItem = new TabItemList();
            tabItem.Add(0);
            tabItem.Add(1);
            tabItem.Add(2);
            tabItem.Add(3);
            tabItem[0].Add(4);
            tabItem[0].Add(5);
            tabItem[0].Add(8);
    
            foreach (var item1 in tabItem)
            {
              Console.WriteLine($"level 1: {item1.Name}");
              foreach (var item2 in item1)
              {
                Console.WriteLine($"  level 2: {item2.Name}");
              }
            }
          }
        }
    
        public class TabItemList : List<TabItemList>
        {
          public void Add(int name) => this.Add(new TabItemList() { Name = name.ToString() });
          public string Name { get; set; }
        }
      }
    }


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    • Marked as answer by CY_Chen Thursday, September 19, 2019 5:25 AM
    Thursday, September 19, 2019 2:38 AM

All replies

  • Hi  CY_Chen, 

    >>I am consider hash table and dictionary I am not sure C# have Those two data structure come from c++

    Is there any data structure can fulfill my need?

    I can call like dictionary give its key to check its data

    The following articles describes some common collection scenarios and the collection classes you can use for those scenarios. If you are new to generic collections, this table will help you choose the generic collection that works the best for your task.

    Collections and Data Structures
    https://docs.microsoft.com/en-us/dotnet/standard/collections/

    Selecting a Collection Class
    https://docs.microsoft.com/en-us/dotnet/standard/collections/selecting-a-collection-class

    Best regards

    Yong Lu


    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.

    Tuesday, September 17, 2019 3:09 AM
    Moderator
  • Hi Yong Lu

    Thanks for answering

    Is List allow two dimension structure

    Like

    List<int> tabItem=new list<int>();
    tabItem.Add(0);
    tabItem.Add(1);
    tabItem.Add(2);
    tabItem.Add(3);
    tabItem[0].Add(4);
    tabItem[0].Add(5);
    tabItem[0].Add(8);

    I want to do 

    tabItem[0].Add(4);
    tabItem[0].Add(5);
    tabItem[0].Add(8);

    And

    for(int I=0;i<tabItem[0].count;i++)
    {
        tabItem[0][i];//I want to get 4 5 8
    }//end for loop 


    Is those possible?


    • Edited by CY_Chen Tuesday, September 17, 2019 8:06 AM
    Tuesday, September 17, 2019 8:01 AM
  • Hi Yong Lu

    Thanks for answering

    Is List allow two dimension structure

    Like

    List<int> tabItem=new list<int>();
    tabItem.Add(0);
    tabItem.Add(1);
    tabItem.Add(2);
    tabItem.Add(3);
    tabItem[0].Add(4);
    tabItem[0].Add(5);
    tabItem[0].Add(8);

    I want to do 

    tabItem[0].Add(4);
    tabItem[0].Add(5);
    tabItem[0].Add(8);

    And

    for(int I=0;i<tabItem[0].count;i++)
    {
        tabItem[0][i];//I want to get 4 5 8
    }//end for loop 


    Is those possible?


    It is not possible.

    Best regards

    Yong Lu


    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.

    Wednesday, September 18, 2019 2:55 AM
    Moderator
  • Hi,
    you can use own class like in this demo:

        internal class Demo
        {
          internal void Execute()
          {
            TabItemList tabItem = new TabItemList();
            tabItem.Add(0);
            tabItem.Add(1);
            tabItem.Add(2);
            tabItem.Add(3);
            tabItem[0].Add(4);
            tabItem[0].Add(5);
            tabItem[0].Add(8);
    
            foreach (var item1 in tabItem)
            {
              Console.WriteLine($"level 1: {item1.Name}");
              foreach (var item2 in item1)
              {
                Console.WriteLine($"  level 2: {item2.Name}");
              }
            }
          }
        }
    
        public class TabItemList : List<TabItemList>
        {
          public void Add(int name) => this.Add(new TabItemList() { Name = name.ToString() });
          public string Name { get; set; }
        }
    


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Wednesday, September 18, 2019 6:39 AM
  • Hi Peter Thanks for answering

    If I try to get tabItem[0] contain number 5 from

    TabItemList tabItem = new TabItemList();
    tabItem.Add(0);
    tabItem.Add(1);
    tabItem.Add(2);
    tabItem.Add(3);
    tabItem[0].Add(4);
    tabItem[0].Add(5);
    tabItem[0].Add(8);



    public class TabItemList : List<TabItemList>
        {
          public void Add(int index) => this.Add(new TabItemList() { Index= index});
          public int Index{ get; set; }
        }


    How to get tabItem[0] contain 5 this number?

    I try to do 

    for(int i=0;i<tabItem[0].count;i++)//tabItem[0].count contain 458 three number =3
    {
         int y=tabItem[0].Index[i];   
    }

    through for loop (i=0 ,i=1 ,i=2) I  want to save 4, 5, 8 into y

    taItem[0].Index[0]=4
    taItem[0].Index[1]=5
    taItem[0].Index[2]=8



    Thanks


    • Edited by CY_Chen Thursday, September 19, 2019 1:29 AM
    Thursday, September 19, 2019 12:54 AM
  • Hi,
    I didn't unterstand your problem. Try the following console demo and describe your problem.

    using System;
    using System.Collections.Generic;
    
    namespace ConsoleApp1
    {
      class Program1
      {
        [STAThread]
        static void Main(string[] args)
        {
          try
          {
            (new Demo()).Execute();
          }
          catch (Exception ex) { Console.WriteLine(ex.ToString()); }
          Console.WriteLine("Continue enter key");
          Console.ReadKey();
        }
    
        internal class Demo
        {
          internal void Execute()
          {
            TabItemList tabItem = new TabItemList();
            tabItem.Add(0);
            tabItem.Add(1);
            tabItem.Add(2);
            tabItem.Add(3);
            tabItem[0].Add(4);
            tabItem[0].Add(5);
            tabItem[0].Add(8);
    
            foreach (var item1 in tabItem)
            {
              Console.WriteLine($"level 1: {item1.Name}");
              foreach (var item2 in item1)
              {
                Console.WriteLine($"  level 2: {item2.Name}");
              }
            }
          }
        }
    
        public class TabItemList : List<TabItemList>
        {
          public void Add(int name) => this.Add(new TabItemList() { Name = name.ToString() });
          public string Name { get; set; }
        }
      }
    }


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    • Marked as answer by CY_Chen Thursday, September 19, 2019 5:25 AM
    Thursday, September 19, 2019 2:38 AM