ändern backcolor-Zeile in datagridview

Problem habe ich mit wechselnden Zeilen Farbe in Windows Forms. Ich habe es mit Spalten und versucht, das gleiche für die Zeilen, aber es hat nicht funktioniert. Kann mir jemand zeigen, wie es zu tun?

Mein Code bisher:

 public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        abc();
    }

    void abc()
    {
        DataTable hh = new DataTable();
        hh.Columns.Add("1", typeof(string));
        hh.Columns.Add("2", typeof(string));
        hh.Columns.Add("3", typeof(string));

        hh.Rows.Add(new object[] { "a", "b", "c" });
        hh.Rows.Add(new object[] { "a1", "b1", "c1" });
        hh.Rows.Add(new object[] { "a2", "b2", "c2" });

        dataGridView1.DataSource = hh;

        foreach (DataGridViewRow dr in dataGridView1.Rows) //trying to change all rows to orange
            dr.DefaultCellStyle.BackColor = Color.Orange;  //but it doesn't work

        dataGridView1.Rows[0].DefaultCellStyle.BackColor = Color.Orange; //doesn't work
        dataGridView1.Refresh();
        dataGridView1.Update();

        dataGridView1.Columns[0].DefaultCellStyle.BackColor = Color.Beige; //this works


    }
}

InformationsquelleAutor Le Viet Hung | 2013-01-25

Schreibe einen Kommentar