WinForm Datagrid Control
-
1.I hava Datagrid control in window forms, which bind data from datatable. I don't want to show "id" field, but I think I need it for click event on a certain row in datagrid. How can I hide this field but still can get value from it? 2. How can I specify the column width for each column? Thanks. Beginner
-
1.I hava Datagrid control in window forms, which bind data from datatable. I don't want to show "id" field, but I think I need it for click event on a certain row in datagrid. How can I hide this field but still can get value from it? 2. How can I specify the column width for each column? Thanks. Beginner
For #1 give this a shot
// columnIndex must be set to a number.
int columnIndex = 1;
// remove the second column
GridColumnStylesCollection myGridColumns;
myGridColumns = dataGrid1.TableStyles[0].GridColumnStyles;
myGridColumns.RemoveAt( columnIndex );For #2 there try this block.
GridColumnStylesCollection myGridColumns;
myGridColumns = dataGrid.TableStyles[0].GridColumnStyles;foreach(DataGridColumnStyle style in myGridColumns)
{
// GetColumnWidth takes the header name and returns the width the column should be
style.Width = GetColumnWidth(style.HeaderName);
}HTH, James Simplicity Rules!