【发布时间】:2014-09-05 13:41:10
【问题描述】:
添加文件后 - 我想要一个选中的复选框,而不是在 dataGridView 列中看到“是”。我该怎么做?
我在做什么:
在“主”表单中,当我单击“添加”时,frmAddVideo 会出现在我需要插入所有视频信息的位置。在 frmAddVideo 表单中,有一个组合框,其值为“是”和“否”,用于表示视频的可用性。 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.
我提供了代码,但看到它不起作用,我认为这是不正确的。我没有提供主要形式,因为它没有必要。
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 语句。
非常感谢大家!
J
【问题讨论】:
-
您发布了很多代码,但我在其中的任何地方都找不到您的 DataGridView 控件。即使您的添加视频代码也没有显示它被添加到任何东西。让您的可用性属性是一个字符串可能是一个错误,因为您将其视为布尔值。
标签: c# winforms checkbox datagridview