2014-09-05 97 views
0

添加文件後 - 我沒有在dataGridView列中看到「是」,而是想要一個Check複選框。我該怎麼做才能做到這一點?dataGridView中的複選框

我在做什麼:

在「主」的形式當我點擊「添加」,然後在出現frmAddVideo,我需要插入所有視頻的信息。在frmAddVideo表單中,有一個組合框,其值爲「是」和「否」,表示視頻的可用性。當選擇「是」時,添加dataGridVideo中顯示的視頻後,dataGridView中必須有一個「勾號」複選框,反之亦然,因爲它不可用。

我提供的代碼,但我不認爲它是正確的,看到它不起作用。我沒有提供主表格,因爲它沒有必要。

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); 

       //AVAILABILITY 
       //How do I make this to apear as a checkbox in the dataGridView? 
       NewVideo.Availability = Convert.ToString(comboBox2.SelectedItem); 

       if (NewVideo.yesNo() == true) 
        MessageBox.Show("Yes"); 
       else 
        MessageBox.Show("No"); 


       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.Availability); 
     } 
    } 
} 

namespace A6 
{ 
    [Serializable] 

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

     //bool mshowing3D; 

     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; } 
     } 

     public string Availability 
     { 
      get { return mAvailability; } 
      set { mAvailability = value; } 
     } 

     public bool yesNo() 
     { 
      if (mAvailability == "Yes") 
      { 
       return true; 
      } 
      else 
      { 
       return false; 
      } 
     } 

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

應用程序的其餘部分完美的作品。只是不知道如何處理bool語句的可用性。

非常感謝你們!

Ĵ

+0

你發佈了很多代碼,然而,我無法在其中的任何地方找到你的DataGridView控件。即使您的添加視頻代碼也不會顯示它被添加到任何內容。讓您的可用性屬性成爲一個字符串可能是一個錯誤,因爲您將它視爲一個布爾值。 – LarsTech 2014-09-05 14:40:01

回答

0

杉杉在表單中創建一個新的複選框是這樣的:

<asp:CheckBox ID="SelectCheckBox" runat="server" /> 

然後,更改消息框控件一個CheckBox和值傳遞給它的checked屬性:

//AVAILABILITY 
       //How do I make this to apear as a checkbox in the dataGridView? 
       NewVideo.Availability = Convert.ToString(comboBox2.SelectedItem); 

           SelectCheckBox.Checked = NewVideo.yesNo(); 
+0

也可以使複選框不可用,以便用戶更改,在CodeBehind中將其Enabled屬性設置爲false; – 2014-09-05 13:53:47

+0

是否有另一種創建複選框的方法?我問,因爲我目前沒有使用服務器或任何數據庫。 – JBTGE 2014-09-05 14:09:21

+0

這個問題被標記爲'Winforms'。 – TaW 2014-09-05 16:58:17