Dynamic Button Click event

  • Thread starter Thread starter Carlo Goretti
  • Start date Start date
C

Carlo Goretti

Guest
hey! Im trying to make so if you click on a dynamic button then it gets the text of a dynamic Label. but dont know how to make it.. 10 Buttons and 10 Labels.

for (int i = 0; i < RollerBeteckning.Count(); i++)
{


//service.LoadPropertiesForItems(appointments.Items, PropertySet.FirstClassProperties);
rollerBeteckningLbl = new Label();
rollerBeteckningLbl.Name = "TaBortLblDynamisk " + i;
rollerBeteckningLbl.Font = new Font(rollerBeteckningLbl.Font.FontFamily, 10);
rollerBeteckningLbl.Text = RollerBeteckning;
rollerBeteckningLbl.AutoSize = true;
//test.Add(appointments.Items.TextBody.Text);
rollerBeteckningLbl.BorderStyle = BorderStyle.FixedSingle;
rollerBeteckningLbl.Location = new Point(BefintligaRollerLbl.Location.X, BefintligaRollerLbl.Location.Y + BefintligaRollerLbl.Height + 15 + (i * 25));

//lstChckBox.Add(box);
//box.CheckedChanged += new EventHandler(chck_CheckedChanged);

rollerTaBortBtn = new Button();
rollerTaBortBtn.Name = "TaBortBtnDynamisk " + i;
rollerTaBortBtn.Text = "Ta bort";
rollerTaBortBtn.Size = new Size(75, rollerBeteckningLbl.Height);
rollerTaBortBtn.Location = new Point(rollerBeteckningLbl.Location.X + rollerBeteckningLbl.Width + 20, BefintligaRollerLbl.Location.Y + BefintligaRollerLbl.Height + 15 + (i * 25));
rollerTaBortBtn.FlatStyle = FlatStyle.Flat;
rollerTaBortBtn.FlatAppearance.BorderSize = 0;
rollerTaBortBtn.BackColor = Color.FromArgb(254, 66, 2);
rollerTaBortBtn.ForeColor = Color.White;
rollerTaBortBtn.Click += new EventHandler(Btn_click);
TaBortRollBtnLista.Add(rollerTaBortBtn);
Controls.Add(rollerBeteckningLbl);
Controls.Add(rollerTaBortBtn);
}

void Btn_click(object sender, EventArgs e)
{

for (int i = 0; i < TaBortRollBtnLista.Count(); i++)
{

try
{

queryString = "exec Ta_Bort_Användare_Roller '" + AnvändarId + "', '" + RollTypIDLista + "' ";

conn = new SqlConnection(connetionString);
SqlCommand commandProcessID = new SqlCommand(queryString, conn);

conn.Open();
reader = commandProcessID.ExecuteReader();

reader.Close();
conn.Close();



}
catch (SqlException sql)
{

MessageBox.Show("Följande fel: \n\n" + sql);
}

}
MessageBox.Show("Nu är Rollen borttagen!");

}
I get all the buttons here.. I just want to do this for the clicked one..

Continue reading...
 

Similar threads

C
Replies
0
Views
155
Carlo Goretti
C
Back
Top