Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

populate textbox using hashtable

$
0
0
I'm creating an agenda program using windows form application, I'm trying to load data from a file into a hash table and display this data into text boxes. The labels on the text boxes are dates but these dates are of the form (dd MMMM dddd e.g 30 November Friday) and are used as key values for the hash table. The dates in the file are of the form (dd MM yyyy). A sample of the data in the file is shown.

10/07/2012,Will go to swimming at 10.30 *

30/11/2012,Will go to swimming at 15.30 *

When I load the form, the data should be shown in the corresponding textbox. For example Will go to swimming at 15.30 * must be shown under text box with label "30 November Friday" (because it corresponds to date 30/11/2012). My code so far is this:-

  while ((line = sr.ReadLine()) != null)
             {
                 string[] inData = line.Split(',');
                 key = inData[0];
                 value = inData[1];
                 hT.Add(key, value);

                 foreach (DictionaryEntry dataEntry in hT)
                 {
                     //Will throw a FormatException if 'dataEntry.Key' doesn't represent a valid date format
                     
                     DateTime keyAsDate = Convert.ToDateTime(key);

                     //This overload of 'ToString' uses CurrentCulture
                     string comparisonKey = keyAsDate.ToString("dd MMMM dddd");
                     
                     if (label1.Text.Equals(comparisonKey, StringComparison.OrdinalIgnoreCase))
                     {
                         textBox1.Text = dataEntry.Value.ToString();
                        
                     }

                     if (label2.Text.Equals(comparisonKey, StringComparison.OrdinalIgnoreCase))
                     {
                        
                         textBox2.Text = dataEntry.Value.ToString();
                        
                     }

                     if (label3.Text.Equals(comparisonKey, StringComparison.OrdinalIgnoreCase))
                     {
                         textBox3.Text = dataEntry.Value.ToString();
                         
                     }




Nothing is displayed after i load the form. The textBoxes are empty. I just can't seem to place the error. How can i fix this?

Thank you

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>