thanks for looking at my question. I have a Object called UIChoice
namespace uitest
{
public class UIChoice
{
public String name {get; set;}
public Button yes { get; set; }
}
}
then I have a Form1
with a DataGridView
(I call it grdChoice
) like this
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);
}
}
}
what should happen (in my imagination) is that the DataGridView
should notice that it is a DataGridViewButtonColumn
and notice it has been given a Button and use it. But it doesn't. The problem for me is this is a replacement code. In real life the UIChoice
object is heavily fortified with methods and the DataGridView
was (originally) merely meant to replace a hand cranked panel of horizontally incrementing buttons (which became too "massive") the sad part is as I have written it this DataGridView
doesn't work i.e. when I construct a BindingList object it doesn't seem to "notice" or "care" that I am giving it a button .. how do I make the DataGridView
care that I already sent it the Buttons
it needs?