C# easier ways to filter values in data-grid by month Goal:
My goal is to filter datagrid by selected month from dropdown options.
January, February, March etc...
I'd like to know if there are easier methods to my current method..
Code:
public Schedule()
{
    InitializeComponent();
    RefreshGrid();

    Dictionary&lt;string, string&gt; allOptions = new Dictionary&lt;string, string&gt;();
    allOptions.Add(&quot;1&quot;, &quot;All&quot;);
    allOptions.Add(&quot;2&quot;, &quot;January&quot;);
    allOptions.Add(&quot;3&quot;, &quot;February&quot;);
    allOptions.Add(&quot;4&quot;, &quot;March&quot;);
    allOptions.Add(&quot;5&quot;, &quot;April&quot;);
    allOptions.Add(&quot;6&quot;, &quot;May&quot;);
    allOptions.Add(&quot;7&quot;, &quot;June&quot;);
    allOptions.Add(&quot;8&quot;, &quot;July&quot;);
    allOptions.Add(&quot;9&quot;, &quot;August&quot;);
    allOptions.Add(&quot;10&quot;, &quot;September&quot;);
    allOptions.Add(&quot;11&quot;, &quot;October&quot;);
    allOptions.Add(&quot;12&quot;, &quot;November&quot;);
    allOptions.Add(&quot;13&quot;, &quot;December&quot;);

    Months.DataSource = new BindingSource(allOptions, null);
    Months.DisplayMember = &quot;Value&quot;;
    Months.ValueMember = &quot;Key&quot;;

}

public void RefreshGrid()
{
    string value = &quot;&quot;;

    // Select All
    if(Months.SelectedIndex == 0)
    {
        value = &quot;&quot;;
    }
    // Select * from January
    if(Months.SelectedIndex == 1)
    {
        value = &quot; where month(date_purchased) = 1;&quot;;
    }
    // Select * from February
    if (Months.SelectedIndex == 2)
    {
        value = &quot; where month(date_purchased) = 2;&quot;;
    }
    //... and son on...

    // MySQL connection string
    using (var conn = new MySqlConnection(ConnectionString.ConnString))
    {
        //Select query
        using (var mySqlDataAdapter = new MySqlDataAdapter(&quot;select * from table &quot;+ value +&quot;;&quot;, conn))
        {
            using (var dataSet = new DataSet())
            {
                DataSet DS = new DataSet();
                mySqlDataAdapter.Fill(DS);

                //Assign headers to Data Grid View
                scheduleData.DataSource = DS.Tables[0];
                scheduleData.Columns[0].HeaderText = &quot;ID&quot;;
                scheduleData.Columns[1].HeaderText = &quot;Equipment Name&quot;;
                scheduleData.Columns[2].HeaderText = &quot;Date Purchased&quot;;


                //Set visibility to false for the columns to work in the background
                scheduleData.Columns[0].Visible = false;
            }
        }
    }
}

private void Months_SelectedIndexChanged(object sender, EventArgs e)
{
    RefreshGrid();
}

This idea does work - but Seems like there is too much unnecessarily code. But I cannot think of an alternative.
Why not something simple like this:
var filter = Months.SelectedIndex == 0 ? null : 
    $&quot; where month(date_purchased) = {Months.SelectedIndex};&quot;

Also that dictionary initialization code is a lot of copy &amp; paste, you could easily write it like this:
var allOptions = new Dictionary&lt;string, string&gt;()
{
    [&quot;0&quot;] = &quot;All&quot;
};

int idx = 1;
foreach(var month in DateTimeFormatInfo.CurrentInfo.MonthNames)
    allOptions.Add((idx++).ToString(), month);

Edit: also don't use data sets if you're only returning one data table, use the table versions of the database API instead.