Goran Bibic

Goran Bibic

  • 475
  • 2.9k
  • 201k

Create dinamicly button in couple columns c#

Apr 6 2018 6:48 AM
Code working fine...
Create dinamicly button in couple columns c#
If I have 22,23,24...buttons to create 5 columns with 5 buttons...and 
  1. SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True");  
  2.            SqlCommand cmd = new SqlCommand("SELECT Concat(ime, cijena_sa_porezom) FROM roba_usluge", con);  
  3.   
  4.            // Getting all the data to ItemTable    
  5.            var da = new SqlDataAdapter(cmd);  
  6.            var ItemTable = new DataTable();  
  7.            da.Fill(ItemTable);  
  8.   
  9.            con.Open();  
  10.            Int32 count = ItemTable.Rows.Count;  
  11.            con.Close();  
  12.   
  13.            int top = 50;  
  14.            int left = 50;  
  15.            for (int i = 0; i < count; i++)  
  16.            {  
  17.                Button button = new Button();  
  18.                button.Left = left;  
  19.                button.Top = top;  
  20.                button.Text = ItemTable.Rows[i][0].ToString();  
  21.                this.Controls.Add(button);  
  22.                top += button.Height + 2;  
  23.            } 
 

Answers (4)