title: how do i add items in combobox?
body: <p>i am having a problem. How do i add items in comboBox?</p>
  <p>I already tried this code:</p>
  <pre><code>comboBox1.Items.Add(&quot;--Dates--&quot;);
  comboBox1.SelectedIndex = 0;
  </code></pre>
  <p>but it is cannot add the items in comboBox when i run the program.</p>
  <p>Here is the code:</p>
  <pre><code>public partial class Trans : Form
      {
          string connectionString = @&quot;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\db1.accdb&quot;;
  
          private const int CP_NOCLOSE_BUTTON = 0x200;
  
          private Choices _choice;
  
          private DataSet _ds = new DataSet();
  
          private List&lt;DateTime&gt; _startDate = new List&lt;DateTime&gt;();
          private List&lt;DateTime&gt; _endDate = new List&lt;DateTime&gt;();
  
          int startDate;
          int endDate;
  
          public Trans()
          {
              InitializeComponent();
          }
  
          public Trans(Choices _choice)
              : this()
          {
              this._choice = _choice;
          }
  
          private void Trans_Load(object sender, EventArgs e)
          {
              startDate = (int)DateTime.Today.AddYears(5).Subtract(DateTime.Today).TotalDays + 1;
              endDate = (int)DateTime.Today.AddYears(5).Subtract(DateTime.Today).TotalDays + 1;
  
              for (int i = 0; i &lt; startDate; i++)
              {
                  _startDate.Add(DateTime.Today.AddDays(i));
              }
  
              for (int i = 0; i &lt; endDate; i++)
              {
                  _endDate.Add(DateTime.Today.AddDays(i));
              }
  
              StartDateCollection(sender, e);
  
              this.dataGridView1.Columns[&quot;ID&quot;].Visible = false;
              this.dataGridView1.Sort(this.dataGridView1.Columns[&quot;Times&quot;], System.ComponentModel.ListSortDirection.Ascending);
              this.label3.Text = &quot;Welcome, &quot; + UserInformation.CurrentLoggedInUser + &quot; &quot; + &quot; &quot; + &quot;-&quot; + &quot; &quot; + &quot; &quot; + UserInformation.CurrentLoggedInUserType;
              this.label3.ForeColor = System.Drawing.Color.White;
  
              dataGridView1.RowPostPaint += new DataGridViewRowPostPaintEventHandler(this.SetRowNumber);
              dataGridView1.ClearSelection();
          }
  
          private void ViewDatabase(object sender, EventArgs e)
          {
              using (OleDbConnection conn = new OleDbConnection(connectionString))
              {
                  string query = &quot;SELECT [ProductCode], [Quantity], [Description], [SubTotal], [Total], [IssuedBy], [To], [Dates], [Times] FROM [TransRecord]&quot;;
  
                  conn.Open();
  
                  using (OleDbDataAdapter _adapter = new OleDbDataAdapter(query, conn))
                  {
                      _ds.Clear();
                      _adapter.Fill(_ds, &quot;TransRecord&quot;);
                      dataGridView1.DataSource = null;
                      dataGridView1.Refresh();
                  }
  
                  dataGridView1.DataSource = _ds.Tables[0];
  
                  conn.Close();
              }
          }
  
          private void SetRowNumber(object sender, DataGridViewRowPostPaintEventArgs e)
          {
              var grid = sender as DataGridView;
              var rowIdx = (e.RowIndex + 1).ToString();
  
              var centerFormat = new StringFormat()
              {
                  Alignment = StringAlignment.Center,
                  LineAlignment = StringAlignment.Center
              };
  
              var headerBounds = new Rectangle(e.RowBounds.Left, e.RowBounds.Top, grid.RowHeadersWidth, e.RowBounds.Height);
              e.Graphics.DrawString(rowIdx, this.Font, SystemBrushes.ControlText, headerBounds, centerFormat);
          }
  
          private void StartDateCollection(object sender, EventArgs e)
          {
              comboBox1.DataSource = _startDate;
              comboBox1.FormatString = &quot;M/dd/yyyy&quot;;
              comboBox1.FormattingEnabled = true;
          }
  
          private void StartDateCollection_SelectedIndexChanged(object sender, EventArgs e)
          {
              DateTime comboBox1_SelectedDate = Convert.ToDateTime(comboBox1.SelectedValue);
              List&lt;DateTime&gt; tempDate = _endDate.Where(d =&gt; d &gt; comboBox1_SelectedDate).ToList&lt;DateTime&gt;();
              comboBox2.DataSource = tempDate;
              comboBox2.FormatString = &quot;M/dd/yyyy&quot;;
              comboBox2.FormattingEnabled = true;
          }
  </code></pre>
  <p>(.... Other codes)</p>
  <p>I put the Items.Add in the StartDateCollection function, but it is not appear the string that i add in, only appear the dates.</p>
  <p>How do i fix that?</p>
  <p>Thanks.</p>
  <p>Or, i would like to have from first date transaction record.</p>
  <p>Example: I have transaction record on this day <code>24 September 2013</code>, but when i open the program at tomorrow, i cannot open the transaction record on <code>24 September 2013</code>, because the date <code>24 September 2013</code> already disappeared. I want to the combobox items are displaying from the first date of the transaction record.</p>
  <p>I appreciate your answer
  Thank you so much!</p>
  <p>Here is the screenshot:
  <img src="https://i.stack.imgur.com/Swm7w.png" alt="enter image description here" /></p>
  <p>As you can see from the picture above, the Start Date in ComboBox are <code>Date</code>, i want to make a <code>---Dates---</code> before the <code>Date</code> are shown. So it will be something like this (in comboBox)
  ---Dates---
  9/24/2013
  9/25/2013
  ......
  (And so on)</p>