感谢您查看我的问题。我有一个对象叫UIChoice
namespace uitest
{
public class UIChoice
{
public String name {get; set;}
public Button yes { get; set; }
}
}
然后我有一个像这样Form1
的DataGridView
(我称之为grdChoice
)
namespace uitest
{
public class Form1 : Form
{
public BindingList<UIChoice> Choices = new BindingList<UIChoice>();
public Form1 ()
{
InitializeComponent();
DataGridViewTextBoxColumn colName = new DataGridViewTextBoxColumn();
colName.HeaderText = "Name:";
colName.Name = "yestext";
colName.DataPropertyName = "name";
grdChoice.Columns.Add(colName);
DataGridViewButtonColumn colYes = new DataGridViewButtonColumn();
colYes.HeaderText = "Yes:";
colYes.Name = "yesbutton";
colYes.DataPropertyName = "yes";
colYes.FlatStyle = FlatStyle.Popup;
grdChoice.Columns.Add(colYes);
grdChoice.DataSource = Choices;
grdChoice.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
grdChoice.Show();
FillData();
}
private void FillData()
{
UIChoice myChoice = new UIChoice();
Button Yes = new Button();
Yes.Click += ((sender, args) =>
{
MessageBox.Show("try this yes works");
});
Yes.Text = "yes";
myChoice.name = "try this";
myChoice.yes = Yes;
Choices.Add(myChoice);
UIChoice myChoiceA = new UIChoice();
Button YesA = new Button();
YesA.Click += ((sender, args) =>
{
MessageBox.Show("try A yes works");
});
YesA.Text = "yes";
myChoiceA.name = "try A";
myChoiceA.yes = YesA;
Choices.Add(myChoiceA);
}
}
}
应该发生的事情(在我的想象中)是DataGridView
应该注意到它是 aDataGridViewButtonColumn
并注意到它已被赋予一个 Button 并使用它。但事实并非如此。对我来说问题是这是一个替换代码。在现实生活中,该UIChoice
对象被大量方法强化,并且DataGridView
(最初)只是为了替换水平递增按钮的手摇面板(变得过于“庞大”),可悲的部分是我写的这DataGridView
不起作用即,当我构造一个 BindingList 对象时,它似乎没有“注意到”或“关心”我给它一个按钮..我如何使DataGridView
我已经发送它Buttons
需要的关心?