Hi,
Imagine having a Strongly Typed Dataset with 2 tables
* Books (ISBN, BookTitle, BookAuthor)
* Authors (AuthorID, AuthorName)
and a FK relation between the 2 tables (BookAuthor <-> AuthorID)
I need to bind a datagridview to the show the Books table, so I set a Binding Source
LibraryDataSet dsLib = new LibraryDataSet();
BindingSource bsBooks = new BindingSource();
bsBooks.DataSource = dsLib;
bsBooks.DataMember = "Books";
Then Set the DataGridView to be bound to bsBooks.
Now I can view ISBN, BookTitle, and BookAuthor
I need to show the AuthorName instead of the AuthorID.
What's the best practices to do so?
I don't want to add a new table as the combination of the two tables as this will result in 2 copies of the same data which will lead to difficulties maintaining both of them (Updates, ... etc)
Here is what I've tried so far:
1- Add a new unbound column and manually set the value inside a event handler for RowAdded event
for (int i = 0; i < e.RowCount; i++)
{
BooksDataSet.BooksRow book = (BooksDataSet.BooksRow)((DataRowView)(dgv.Rows[e.RowIndex + i]).DataBoundItem).Row;
dgv["colAuthor", e.RowIndex + i].Value = book.AuthorsRow.AuthorName;
}
But this adds a lot of headache with Filtering the BindingSource or Refreshing data
2- Added a new Property to the BooksRow class to return the AuthorName
partial class BooksRow
{
public string AuthorName
{
get
{
return this.AuthorsRow.AuthorName;
}
set
{
this.AuthorsRow.AuthorName= value;
}
}
}
But it doesn't seem to be recognized by the BindingSource
Any better Ideas?