Goran Bibic

Goran Bibic

  • 475
  • 2.9k
  • 200.9k

Auto create image inside button from sql table and dimensio?

Apr 6 2018 9:05 AM
Create
 
  1. private void Form1_Load(object sender, EventArgs e)  
  2.         {  
  3.             // TODO: This line of code loads data into the 'bssDataSet.roba_usluge' table. You can move, or remove it, as needed.  
  4.             this.roba_uslugeTableAdapter.Fill(this.bssDataSet.roba_usluge);  
  5.               
  6.   
  7.             
  8.             SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True");  
  9.             SqlCommand cmd = new SqlCommand("SELECT Concat(ime, cijena_sa_porezom) FROM roba_usluge", con);  
  10.   
  11.             // Getting all the data to ItemTable    
  12.             var da = new SqlDataAdapter(cmd);  
  13.             var ItemTable = new DataTable();  
  14.             da.Fill(ItemTable);  
  15.   
  16.             con.Open();  
  17.             Int32 count = ItemTable.Rows.Count;  
  18.             con.Close();  
  19.   
  20.             int top = 50;  
  21.             int left = 50;  
  22.             for (int i = 1; i <= count; i++)  
  23.                // for (int i = 0; i < count; i++)  
  24.             {  
  25.                 Button button = new Button();  
  26.                 button.Left = left;  
  27.                 button.Top = top;  
  28.                 button.Text = ItemTable.Rows[i-1][0].ToString();  
  29.                // button.Text = ItemTable.Rows[i][0].ToString();  
  30.                 this.Controls.Add(button);  
  31.                 if (i % 5 == 0)  
  32.                 {  
  33.                     left = 50;  
  34.                     top += button.Height + 2;  
  35.                 }  
  36.                 else  
  37.                 {  
  38.                     left += button.Width + 2;  
  39.                 }  
  40.                 // top += button.Height + 2;  
  41.             }  
  42.         } 
 

Answers (5)