views:

625

answers:

1

I have a three-tier Windows Forms DB application in VB.NET. I'm using VS 2005.

I'd like to display records in a table in a DataGridView. I can already display the records as is by binding the DataSource to the business class that talks to the DB class:

Dim assetList as List(Of Asset)
assetList = DB_Asset.GetAssetListOrderByID_Asset 
AssetDataGridView.DataSource = assetList

"Asset" is my business class, and "DB_Asset" is my DB class that queries the DB to return assetList.

Now, Asset has members something like this:

Private m_ID_Asset As Integer
Private m_CategoryID As Integer
Private m_CustodianID As Integer
Private m_ManufacturerID As Integer
Private m_SignedOutToID As Integer
Private m_DefaultLocationID As Integer
Private m_CurrentLocationID As Integer
Private m_DateAcquired As Date
Private m_DateEntered As Date
Private m_EnteredByID As Integer

m _ ID _ Asset contains the primary key for the Asset table in the DB, and everything else of the form m_XXXXXXXXXID contains a foreign key to another table in the DB.

So basically what I get now is rows with a whole lot of numbers. It's exactly what's in the Assets table:

ID_Asset  CategoryID  CustodianID  ManufacturerID  SignedOutToID
   1           17          23            14              5

What I'd like to know is if there's an easy way to display the text fields that I've linked to with all of those foreign keys:

ID_Asset  CategoryName  CustodianName  Manufacturer  SignedOutTo
   1       Soda - Diet      John       Coca-Cola        Fred

Anyone with experience here have any tricks?

Thanks in advance!

+2  A: 

If you have a List(Of Asset) then you basically just change your query DB_Asset.GetAssetListOrderByID_Asset so you are doing your required joins in there and assigning the values out of that property to assetList.

You would want to add something like m_CustomerName As String to your Asset class, along with whatever else you'll be retrieving so you have a place to put the data.

If you can't change your Asset class you probably want to wrap something around it that gets all those strings for you before you bind.

jarrett
OK, that had crossed my mind. I just saw pages upon pages of methods and properties for DataGridView and thought there might be a magical DataGridViewDoWhatJohnWWants in there. ;)
John at CashCommons
This worked well. Thanks!
John at CashCommons