У меня есть форма с элементом управления списком и несколькими кнопками. Когда я нажимаю на одну из кнопок, появляется пользовательский элемент управления с кнопками (addButtons.cs).
Код: Выделить всё
///making the buttons on the usercontrol
internal class AddButton
{
ublic void New(UserControl user, String text, int Location_X, int Location_Y, String stringPath, string price)
{
System.Windows.Forms.Button button = new System.Windows.Forms.Button
{
Text = text,
............
Image = System.Drawing.Image.FromFile(stringPath)
};
//when the button is clicked
button.Click += BTNclick;
user.Controls.Add(button);
user.CreateControl();
// button.Click += new System.EventHandler(OnClick);
}
public void BTNclick(object sender, EventArgs e)
{
System.Windows.Forms.Button clickedbtn = sender as System.Windows.Forms.Button;
//frmHoofd is my Form
frmHoofd frmHoofd = new frmHoofd();
string mail= clickedbtn.Text;
string price= clickedbtn.Name;
string count= "1";
string[] array = { mail, count, price};
frmHoofd.UpdatingListView(array);
}
Код: Выделить всё
namespace KassaSystem1._1
{
// public delegate void EventHandler (string gerecht, string prijs);
public partial class frmHoofd : Form
{
private ContrlVoorgerechten u1;
delegate void MyDelegate(string[] array);
public frmHoofd()
{
InitializeComponent();
}
//updating the listview control calling from the class addButton.cs
public void UpdatingListView(string[] array)
{
if (this.lstBesteld.InvokeRequired)
{
this.lstBesteld.Invoke(new MyDelegate(UpdatingListView), new object[] { array });
}
else
{
ListViewItem lvi = new ListViewItem(array[0]);
lvi.SubItems.Add(array[0]);
lvi.SubItems.Add(array[1]);
lvi.SubItems.Add(array[2]);
//i see the string text appears correctly in the messagebox
MessageBox.Show("mail: " +array[0] + " count: " +array[1]+ " price: " + array[2]);
// lstBesteld.BeginUpdate();
lstBesteld.Items.Add(lvi);
// lstBesteld.EndUpdate();
}
}
//calling the usercontrol
private void btVoorgerechten_Click(object sender, EventArgs e)
{
u1 = new ContrlVoorgerechten() ;
//u1.Dock = DockStyle.Fill;
u1.Width = 750;
u1.Height = 477;
u1.Location = new Point(430, 165);
this.Controls.Add(u1);
Что я делаю не так?
У меня нет никаких ошибок, но в элементе управления списком ничего не отображается.
Что я делаю не так?
Подробнее здесь: https://stackoverflow.com/questions/787 ... ther-class