Search code examples
c#windowsvisual-studioformswindows-application-packaging

Display a button when making a list of buttons for category from table database


I wrote the code correctly but I don't know what the problem is.

Code:

    private void AddCategory()
    {
        string qry = "select * from category";

        SqlCommand cmd = new SqlCommand(qry, MainClass.con);

        SqlDataAdapter da = new SqlDataAdapter(cmd);

        DataTable dt = new DataTable();
        da.Fill(dt);

        categoryPanel.Controls.Clear();

        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                //Button b = new Button();
                Guna.UI.WinForms.GunaButton b = new Guna.UI.WinForms.GunaButton();
                b.BackColor = Color.FromArgb(50, 55, 89);
                b.Size = new Size(134, 45);
                //b.ButtonMode = Guna.UI.WinForms.Enums.ButtonMode.RadioButton;
                //  b. = Guna.UI.WinForms.GunaRadioButton;
                b.Text = row["catName"].ToString();
                categoryPanel.Controls.Add(b);   
            }
        }
        else
        {
            Label lbl = new Label();
            lbl.Text = "No Category Found!";
            categoryPanel.Controls.Add(lbl);
        }
    }

Database :

Result :

I want the result to be all category as buttons


Solution

  • I changed tool from (Panel) to (FlowLayoutPanel)