0

I have two tables: Transactions and Accounts.

Transaction has a foreign key IDAccount from Accounts Table.

I assign datasource property of Datasource property of Datagridview to Transactions Table.

I want to Accounts.description insead of IDAccount in Datagridview.

What must I do?

David Hall
  • 32,624
  • 10
  • 90
  • 127
Tabriz Atayi
  • 5,880
  • 7
  • 28
  • 33

1 Answers1

1

There is a solution to this problem offered here which involves doing some custom code to inspect each property and determine if it belongs to the main bound object or to a child object.

This looks like a good solution except it doesn't support editing or sorting based on these properties.

Another approach (which I would probably recommend since it is simpler) is to introduce an AccountDescription property to your Transaction object.

public class Transaction
{
    private Account _account

    public string AccountDescription
    {
        get { return _account.description; }
        set { _account.description = value; }
    }
}

You might also need to implement some custom INotifyPropertyChanged code so databinding works nicely.

David Hall
  • 32,624
  • 10
  • 90
  • 127