How to edit the datagridview column if it was populated using a dataset? I would like to edit the column header text and width.

Edited 6 Years Ago by AngelicOne: n/a

One method for changing the column header is to change the name of the column as it's pulled from the DB with the "AS" modifier.

As for the width it can be dynamically set with the equivalent of:

dataGridView1.Columns[0].Width

Hope that helps :)

I tried this

Step 1. Go to Properties > Misc > Columns. This shows the Edit Columns dialog box. Click on the Add... button the bottom left. A screenshot is shown at top of this article.

Step 2. Change the Unbound column. An Unbound column is one that is not directly linked to a DataSource. Note that sometimes it is easier to use the DataSource directly.

Step 3. Change the header text. The text you type into the Header text: text box will ensure that the text is always shown. This means you can display a different form of the column's name than is in the actual DataTable and database.

Step 4. Finally, change the properties. You need to change the properties of the DataGridViewColumn in the dialog box that appears. I set 110px as the width, and AutoSizeMode of None.

That works too, and as indicated in that "Note that sometimes it is easier to use the DataSource directly" which in it's own way can be accomplished in the way I said with an "AS" modifier in the select string. As for the width, you simply did it the 'front-end' way while I was doing it the 'back-end' way :twisted: Glad you got it sorted though.

This question has already been answered. Start a new discussion instead.