using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace FileReadFormsAuto
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem.Equals("TV"))
            {
                comboBox2.Items.Clear();
                comboBox2.Items.Add("TV.ON");
                comboBox2.Items.Add("TV.OFF");
                comboBox2.Items.Add("TV.MUTE");
            }

            else if(comboBox1.SelectedItem.Equals("FRIDGE"))
            {
                comboBox2.Items.Clear();
                comboBox2.Items.Add("FRIDGE.ON");
                comboBox2.Items.Add("FRIDGE.OFF");
            }

            else if(comboBox1.SelectedItem.Equals("AC CONTROL"))
            {
                comboBox2.Items.Clear();
                comboBox2.Items.Add("AC.ON");
                comboBox2.Items.Add("AC.MEDIUM");
                comboBox2.Items.Add("AC.OFF");
            }

            else if(comboBox1.SelectedItem.Equals("VOLUME CONTROL"))
            {
                comboBox2.Items.Clear();
                comboBox2.Items.Add("VOLUP");
                comboBox2.Items.Add("VOLDOWN");
            }

            else if (comboBox1.SelectedItem.Equals("CHANNEL CONTROL"))
            {
                comboBox2.Items.Clear();
                comboBox2.Items.Add("CHANNEL+");
                comboBox2.Items.Add("CHANNEL-");
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string key = string.Empty;
                string[] lines = File.ReadAllLines(@"C:\SUBS\FileReadFormsAuto\FileReadFormsAuto\TVOP.txt");
                Hashtable tab = new Hashtable();

                foreach (string line in lines)
                {
                    string[] items = line.Split('=');
                    tab.Add(items[0], int.Parse(items[1]));
                }

                if (tab.ContainsKey(comboBox2.SelectedValue))
                {
                    textBox1.Text = tab[comboBox2.SelectedValue].ToString();
                }

                else
                {
                    MessageBox.Show("Invalid Key or Command Selected....\nPlease Select A Valid Device & Operation");
                }
            }

            catch (Exception Ex)
            {                
                MessageBox.Show(Ex.Message);
            }
        }
    }
}

Here is my doubt

here i included values in combobox2,If i select the key in it the respecting value should be printed in the textbox1 by selecting the key in the combobox2

It looks like you're processing this stuff twice -- once in the "if" statements and once for the HashTable.

What does the file contain?
From your parse method, it looks like a string, and equal sign and a number.
Is that correct?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.