Change DataGridView column style at runtime in C#


How to change DataGridview column style at runtime in Visual Studio C#.Net?

Simply get the column from the Gridview with the help of subclass of GridView. The code will look like

DataGridViewComboBoxColumn products = new DataGridViewComboBoxColumn();
products = (DataGridViewComboBoxColumn)dataGridView1.Columns[ITEM.Index];
products.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
products.FlatStyle = FlatStyle.Flat;

All changes made to the object products will change the dataGridView1.Columns[ITEM.Index] since the object point to the dataGridveiw column ITEM.

* It resembles pointers in C, where a value changes in a pointer also reflect the variable.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.