• Advertisement
Sign in to follow this  

C# DataGridView and Cell Style??

This topic is 3917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

C# Gurus, I am creating a simple DataGridView table and trying to set the background colors for some rows, as shown in the code below. Somehow, the last two lines of code don't seem to have any effects when the application is executed. Does anyone know why? I notice if these two lines were put inside a button click function, then they do work.
       public Form1()
        {
            InitializeComponent();

            initTable();
        }

        private void initTable()
        {
            m_dataset.Tables.Add("my table");

            m_dataset.Tables[0].Columns.Add("A");
            m_dataset.Tables[0].Columns.Add("B");

            for(int i=0; i<10; i++)
                m_dataset.Tables[0].Rows.Add(i*10, i*20);

            DataView dv = new DataView(m_dataset.Tables[0]);
            dataGridView1.DataSource = dv;

            dataGridView1.Rows[3].DefaultCellStyle.BackColor = Color.Green;
            dataGridView1.Rows[4].DefaultCellStyle.BackColor = Color.Green;
        }


Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement