In the combo box I can get it to load all the conversions to the combo box. But, when I click a conversion from the combo box it changes the data to null for some reason. I am not sure if anyone can help me without looking at all my code. But I thought it was worth a shot. I am trying to select a conversion I.e feet to miles and have the "feet" be in the first label and the "miles" be in the second. Here is the code for the click event of the combo box:
public void CmboBxConversion_SelectedIndexChanged(object sender, EventArgs e)
{
//This is not working. If I were to say change the conversion.From to "hello world" the label text does change to hello world.
//But, as is it is it changes it to a null.
Conversion conversion = new Conversion();
Lbl1stConv.Text = conversion.From; //these are labels
LblSecondConv.Text = conversion.To;
}
//this is my Conversion class
public class Conversion
{
public string From { get; set; }
public string To { get; set; }
public decimal Multiplier { get; set; }
public string GetDisplayText(string sep)
{
return From + ("|") + To + ("|") + Multiplier;
}
public string GetCmboBxText(string sep)
{
return From + (" to ") + To;
}
}
//this is how I am loading the combo box
private void Conversion_Load(object sender, EventArgs e)
{
conversions = ConversionDB.GetConversions();
FillConversionComboBox();
}
//here is the method used to fill the combobox
private void FillConversionComboBox()
{
CmboBxConversion.Items.Clear();
foreach (Conversion c in conversions)
{
CmboBxConversion.Items.Add(c.GetCmboBxText("\n"));
}
}
//this is a data base class that the textfile is pulling data
public static class ConversionDB
{
public const string Path = @"..\..\Conversions.txt";
//public const string Path = Dir + "Conversions.txt";
public static List<ConversionList> GetConversions()
{
StreamReader textIn = new StreamReader(
new FileStream(Path, FileMode.Open, FileAccess.Read));
List<ConversionList> conversions = new List<ConversionList>();
while (textIn.Peek() != -1)
{
string row = textIn.ReadLine();
string[] columns = row.Split('|');
ConversionList conversion = new ConversionList();
conversion.From = columns[0];
conversion.To = columns[1];
conversion.Multiplier = Convert.ToDecimal(columns[2]);
conversions.Add(conversion);
}
textIn.Close();
return conversions;
}