What I want to do is add videos to a list available for rent.

In the “main” form when I click “Add” then the frmAddVideo appears where I need to insert all the video’s information. (This works 100% but…) In the frmAddVideo form there is a comboBox with values “Yes” and “No” for the availability of the video. When “Yes” is selected then the video displayed in the dataGridVideo after it is added, there must be a “ticked” checkbox in the dataGridView and vice versa for when it’s not available.

Also when I click "View" on the main form I can view all the video's information. In this form it gives all the video's info and the availability must say "Yes" in the ComboBox if the video is checked in the dataGridView.

How can I do all this with a bool statement for availability and how will it look in my class? I provided code but I don’t think it is correct seeing that it does not work. I am not providing the main form because it is not necessary.

Video class

namespace A6
{
    [Serializable]

    class Video
    {
        private string mTitle;
        private string mCategory;
        private int mYearReleased;
        private double mRunTime;

        //bool mAvailability;


        public string Title
        {
            get { return mTitle; }
            set { mTitle = value; }
        }

        public string Category
        {
            get { return mCategory; }
            set { mCategory = value; }
        }

        public int YearReleased
        {
            get { return mYearReleased; }
            set { mYearReleased = value; }
        }

        public double RunTime
        {
            get { return mRunTime; }
            set { mRunTime = value; }
        }

        //DO AVAILABILITY


        //CONSTRUCTOR
        public Video()
        {
            mTitle = "No Name";
            mCategory = "No Category";
            mYearReleased = 0;
            mRunTime = 0;
        }
    }
}

frmAddVideo

namespace A6
{
    public partial class FrmAddVideo : Form
    {
        internal Video NewVideo;
        public FrmAddVideo()
        {
            InitializeComponent();
        }

        //ADD VIDEO
        private void button1_Click_1(object sender, EventArgs e)
        {
                NewVideo = new Video();

                NewVideo.Title = textBox1.Text;
                NewVideo.Category = Convert.ToString(comboBox1.SelectedItem);
                NewVideo.YearReleased = Convert.ToInt32(numericUpDown1.Value);
                NewVideo.RunTime = Convert.ToDouble(textBox2.Text);

                //STILL HAVE TO IMPLEMENT THE AVAILABILITY???

                MessageBox.Show("Video added");
                this.Close();
        }
    }
}

frmViewVideo

namespace A6
{
    public partial class frmViewVideo : Form
    {
        internal Video NewVideo;
        public frmViewVideo()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmViewVideo_Load(object sender, EventArgs e)
        {
            textBox1.Text = NewVideo.Title;
            textBox2.Text = Convert.ToString(NewVideo.RunTime);
            numericUpDown1.Value = NewVideo.YearReleased;
            comboBox1.SelectedItem = Convert.ToString(NewVideo.Category);

            //comboBox2.SelectedItem = Convert.ToString(NewVideo.BOOL METHOD??);
        }
    }
}

The rest of the application works perfectly. Just can't figure out what to do with the bool statement for availability.

Thanks a lot guys!

J

I'm not entirely sure I understand the problem. A bool property will display appropriately as a checkbox by default in a DataGridView. So you'd add such a property:

bool Availability { get; set; }

Then convert the result of the combobox as necessary (varies depending on how you've got the combobox set up):

// If the items are the strings "Yes" and "No"
Newvideo.Availability = comboBox2.SelectedItem.ToString() == "Yes";

Haha, that pretty much did the trick...

But now the problems lies with when I view the video information in the other form (not on the dataGrid) I can't seem to get to display when the checkbox is checked it must display yes. And when it is unchecked it must say no.

Something like this:

            if (NewVideo.Availability.ToString() == "Yes")
            {
                comboBox2.SelectedItem = "Yes";
            }
            else
            {
                comboBox2.SelectedItem = "No";
            }

but its not working?

No matter. I figured it out by doing this.

if (NewVideo.Availability == true)
{
    comboBox2.SelectedItem = "Yes";
}
else
{
    comboBox2.SelectedItem = "No";
}
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.