B
Bret Pehrson
Question/issue:
I'm using a custom data source for my (WinForms) datagrid:
public class MyDataSource : IList
{
public void AddRow(string firstName, string lastName);
// ...
}
each row is a:
public class MyDataRow
{
public string FirstName
{
get { return firstName; }
}
private string firstName;
//...
}
Then:
MyDataSource data = new MyDataSource();
data.AddRow("Bret", "Pehrson");
//...
grid.DataSource = data;
Now, everything displays fine in the DataGrid. I'm not using any designer or
other parameters to set up the columns, just letting the data source and grid
figure that out. The only problem that I have is that I want the DataGrid to
display "First name" as the column header and not "FirstName" as is currently
happening.
What I'd hope would be possible is some attribute on the FirstName property
that would specify the column name, something like
[HeaderText("First name")]
public string FirstName
{
get { return firstName; }
}
Is there such a beast? I've looked and looked, and can't find anything. I
want all of this to be done in the code for the MyDataRow/MyDataSource class.
Thanks
I'm using a custom data source for my (WinForms) datagrid:
public class MyDataSource : IList
{
public void AddRow(string firstName, string lastName);
// ...
}
each row is a:
public class MyDataRow
{
public string FirstName
{
get { return firstName; }
}
private string firstName;
//...
}
Then:
MyDataSource data = new MyDataSource();
data.AddRow("Bret", "Pehrson");
//...
grid.DataSource = data;
Now, everything displays fine in the DataGrid. I'm not using any designer or
other parameters to set up the columns, just letting the data source and grid
figure that out. The only problem that I have is that I want the DataGrid to
display "First name" as the column header and not "FirstName" as is currently
happening.
What I'd hope would be possible is some attribute on the FirstName property
that would specify the column name, something like
[HeaderText("First name")]
public string FirstName
{
get { return firstName; }
}
Is there such a beast? I've looked and looked, and can't find anything. I
want all of this to be done in the code for the MyDataRow/MyDataSource class.
Thanks