TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Behrouz Hosseini
NA
72
0
How to Pass ComboBox items as Cnstructor Parameter
Jul 7 2010 8:48 AM
Hi
Could you please let me know how I can pass a combobox items as constructor parameter?
As you can see from the codes I have a combobox which is loaded by enum FilmType.now I want to create a movie object by constructor Movie() like:
Movie film = new Movie(textBox1.Text, comboBox1.SelectedItem.ToString());
but I can not convert the item type to enum type!
I Have following Classes:
//======================================= Movie.cs
public class Movie
{
public enum FilmType
{
Action,
Comedy,
Horor,
}
private string title;
private FilmType type;
public Movie(string title, FilmType type)
{
this.title = title;
this.type = type;
}
public Movie() { }
public string Title
{
get { return title; }
set { this.title = value; }
}
public FilmType MovieType
{
get { return type; }
set { this.type = value; }
}
public override string ToString()
{
return Title;
}
}
and I have a Form application as below:
//================================== Form1.cs
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Movie film = new Movie(textBox1.Text, comboBox1.SelectedItem.ToString());
istBox3.Items.Add(film);
textBox1.Clear();
textBox1.Select();
comboBox1.SelectedIndex = -1;
}
private void Form1_Load(object sender, EventArgs e)
{
{
foreach (string movieType in Enum.GetNames(typeof(Movie.FilmType)))
{
comboBox1.Items.Add(movieType);
}
}
}
}
//========================================================
Reply
Answers (
1
)
create tree which have common child using C#
Problem is in printing