Jump to content
  • Advertisement
Sign in to follow this  

C# DataGridView and Cell Style??

This topic is 4032 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()


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


            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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!