Reputation: 22956
I have a datagrid for which I set a datasource as a list of classes, the class has several properties which the datagrid uses to create and populate itself with.
I'd like to still make use of this but rename some of the column labels, remove the row buttons (on the left side of the grid) and hide some of the columns.
I'm not sure how to do this or really what to even google?
Upvotes: 1
Views: 198
Reputation: 22956
I ended up using an SQL query to populate the datasource instead of a list, for reasons unknown I couldn't get datagridstyles working when lists<> where the data source but they worked fine when an SqlCeDataAdapater was the source.
Upvotes: 0
Reputation: 2293
this should solve your problem.
Use DataGrid.AutoGeneratingColumn
event to customize the behaviour.
private void DataGridView_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
string headerName = e.Column.Header.ToString();
// No need of customization.
if (headerName == "IAmPerfect")
{
e.Cancel = true;
}
// Columns which requires updating.
if (headerName == "EID")
{
e.Column.Header = "Employee ID";
}
else if (headerName == "EName")
{
e.Column.Header = "Employee Name";
}
}
Upvotes: 2
Reputation: 866
Create a class for your display with properties you want. Add columns to the grid and set fieldnames for columns with the names of properties in your display class. Create a list of your display objects and set that list as grid's data source.
Upvotes: 1