Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

5. Windows Forms Datagrid

5.45 How can I change the width of the row headers or hide them?


You can get at the width and visibility of the header row/column through a DataGridTableStyle. DataGridTableStyle has properties such as RowHeadersVisible and RowHeadersWidth. DataGridTableStyle also controls things like selections colors and GridLine styles.

// Create a table style that will hold the new column style
// that we set and also tie it to our customer's table from our DB
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = "customers";

//hide the column headers
tableStyle.ColumnHeadersVisible = false;

//change width of the row headers
tableStyle.RowHeadersWidth = 100;

// make the dataGrid use our new tablestyle and bind it to our table
dataGrid1.TableStyles.Clear();

dataGrid1.TableStyles.Add(tableStyle);