Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 444147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:14:29+00:00 2026-05-12T21:14:29+00:00

I have a Winform in c# and I’m trying to build a hashtable with

  • 0

I have a Winform in c# and I’m trying to build a hashtable with a list of buttons that I have. IE: Monday0700Button, Monday0730Button, Monday0800Button, and so on.
In the hashtable I am trying to order these, so that if I need to use a button, and the button that follows it, I can use the hashtable key. IE: if I need to color the background of Monday0730 and Monday 0800, I can somehow tell it to find the next key in the list.

How do I add these buttons into a hashtable so that I can use them in this capacity.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:14:30+00:00Added an answer on May 12, 2026 at 9:14 pm

    What you need is probably an OrderedDictionary, though other methods are also possible. I wouldn’t go for a Hashtable, because that’s unordered and requires quite a bit more coding to get ordering information in.

    Use the following to fill an OrderedDictionary (I assumed WinForms buttons, but ASP.NET or other buttons would also work):

    // I assume your buttons are created somewhere
    // or already exist, i.e., they look something like:
    Button MondayXXXButton = new Button();
    MondayXXXButton.Name = "MondayXXXButton";
    MondayXXXButton.Text = "Hello world";
    
    OrderedDictionary buttons = new OrderedDictionary();
    buttons.Add(MondayXXXButton.Name, MondayXXXButton);
    // etc: for each button
    

    Note: you can add the buttons automatically by looping through all controls.

    Then, you can use the following method to find the location of the next ordered item (unfortunately, you cannot get the “next item” without looping, you’ll have to write your own ordered list if you need that):

    Button GetNextButton(OrderedDictionary buttons, string searchThis)
    {
        IEnumerator enumerator = buttons.Keys.GetEnumerator();
    
        for (enumerator.Reset(); enumerator.MoveNext(); )
            if (enumerator.Current == searchThis)
                break;
    
        // if false, nothing was found, or last item was found
        if (enumerator.MoveNext())
            return (Button)enumerator.Current;
        else
            return null;
    }
    

    Finally, use this to get a certain button and retrieve the next one:

    Button someButton = (Button) buttons["MondayYYYButton"];
    Button nextButton = GetNextButton(buttons, "MondayYYYButton");
    

    The advantage of using an OrderedDictionary is that you shouldn’t worry about how you add the items, they’ll be ordered for you.

    Update: slightly expanded explanation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winform app that calls a web service to check for updates.
I have my winform application gathering data using databinding. Everything looks fine except that
I have a winform in vs2008 that contains a DataGridView. The datagrid contains a
I have a winform application that uses some referenced web services to get data.
I have a Managed C++ WinForm that suddenly stopped showing in the VS 2005
I have a Winform application built with C# and .Net 2.0. I have a
I have a Winform with a BackgroundWorker. The BackgroundWorker, among other things, has to
I have a winform with a listbox and a treeview. Once my listbox is
I have a WinForm application built with VS 2008 (C#) and SQL Server Express
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.