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