Jump to content
  • Advertisement
Sign in to follow this  
faculaganymede

C# DataGridView and Cell Style??

This topic is 4130 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
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!