Hey im a newbie too. I'm not seeing enough info on what your doing. Did you create a savefiledialog? Also, I see that the above code basically says if the user selects a month and it is equal to february, it will return 2. Your above code will throw an error because of the space between the =.
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
Look man I'm a beginnger, but i think your problem lies within line 4 inside the {}. I don't know the right answer but I think you need to reference the SelectedIndex in line 4 as well.
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
Hey try to select another month than Feb. and tell me the value it gives you. I might have a theory as to why you are getting -1.
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
Ok well my theory was wrong then... shoot!
I'm thinking the in line four you need a ToString() statement that references the SelectedIndex.
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
wait I think you need
4. set { SelectedIndex = value; }
try it let me know.
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
it's either that last code or something like this-->
set
{
this.comboBox1.Text = value.ToString();
}
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
public enum Test
{
One, Two, Three
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.comboBox1.DataSource = Enum.GetNames(typeof(Test));
}
public Test Test
{
get
{
return (Test)Enum.Parse(typeof(Test), this.comboBox1.Text);
}
set
{
this.comboBox1.Text = value.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(this.Test.ToString());
this.Test = Test.Two;
MessageBox.Show(this.Test.ToString());
}
Set the DropDownStyle of the ComboBox to DropDownList. This will ensure that only the elements already in the list can be selected (no need to check that the text actually is a valid value). Then if you use Enum.GetValues(typeof(BookType)) to fill the combobox then typeComboBox.SelectedItem property will be a value of BookType. So you can use this in the property getter and setter.
So to summarize. You don't have to bind the combobox to a list of text values as long as you use the DropDownList style. Use the SelectedItem property to get an item of the wanted type instead of checking the Text property.
Edit: You may have to check the SelectedItem property for null
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
jamesonh20
Junior Poster in Training
66 posts since Dec 2009
Reputation Points: 22
Solved Threads: 6
First of all, unless you intend to programmatically set the selected index of the combobox, you dont need the set {} value in your property. You can create it as a read only property:
public int selectMonthIndex
{
get { return monthSelection.SelectedIndex; }
}
The way a property works is that the get method should return a value and the set method assigns one. So if you wanted to keep the set method it would be something like set { monthSelection.SelectedIndex = value; } . 'value' is the value assigned to the set method: selectMonthIndex = 3 would result in the selectedIndex being 3.
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246