Home > Blockchain >  C# Button name from datagridview
C# Button name from datagridview

Time:09-26

I want to change the back color of the button. i know this: button1.BackColor = System.Drawing.Color.Yellow;

But I don't know how to get the name of the button from DataGridView. i try this but it is not working

string butttonn = "table" c.ToString(); 
butttonn.BackColor = System.Drawing.Color.Yellow;

i want to if button name existing access database button.BackColor change to green and if button name does not existing button.BackColor change to red.

i dont know english . I hope I was able to express myself.

CodePudding user response:

thank you guys i fixed this:

 // MASA AÇIK MI KAPALI MI ?
        string[] aktifmasalar = new string[dataGridView2.Rows.Count - 1];
        
        for (int c = 0; c < dataGridView2.Rows.Count - 1; c  )
        {
            aktifmasalar[c] = dataGridView2.Rows[c].Cells["Masaad"].Value.ToString();
        }

       
            foreach (DataGridViewRow rows in dataGridView2.Rows)
            {
                if (rows.Cells["Masaad"].Value.ToString() == "MASA 1")
                {
                    masa1.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 2")
                {
                    masa2.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 3")
                {
                    masa3.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 4")
                {
                    masa4.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 5")
                {
                    masa5.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 6")
                {
                    masa6.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 7")
                {
                    masa7.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 8")
                {
                    masa8.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 9")
                {
                    masa9.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 10")
                {
                    masa10.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 11")
                {
                    masa11.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 12")
                {
                    masa12.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 13")
                {
                    masa13.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 14")
                {
                    masa14.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 15")
                {
                    masa15.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 16")
                {
                    masa16.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 17")
                {
                    masa17.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 18")
                {
                    masa18.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 19")
                {
                    masa19.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }
                else if (rows.Cells["Masaad"].Value.ToString() == "MASA 20")
                {
                    masa20.BackColor = System.Drawing.Color.GreenYellow;
                    continue;
                }

           }
        

      
  • Related