Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Add columns with lookup values from id fields in objectlist
posted

 Good evening folks, I'm new here and I hope someone can give me some extra insight into my current situation.

I'll try and be as complete and to the point as possible in describing my situation.

Basically I have a Windows Form UltraWinGrid which I'm populating with List<T>, however, I wish to replace several id-fields by their respective description fields.

Let's scetch my situation with a simple example.

Say I have a List<Customer> and the Customer class includes the usual properties like name, first name, birth date, ...
But also various id fields. The Customer class is a object that gets it's data filled from OR mapping from a persistent storage medium, in my case that's a

SQLServer2005 database, the id fields are basically the relationship fields from the database. Basically Customer object is pretty much an object representation of the persistent table.

So for example:
public class Customer
{
    String name, firstName, PhoneNumber, ...
    int customerId, favColorId, livingPlaceId
}

public class FavoriteColors
{
    int favColorId
    string colorName, hexNotation, string RGBNotation
}

public class LivingPlace
{
    int livingPlaceId
    string country, city, countryCode, postalCode
}

So I have a List<Customer> customers and bind it to my grid in code behind as 'customersGrid.Datasource = customers'
This works fine and my whole system has already been programmed around working like this. So for functionality there's no problem. After all, it's the id values that are used for the programmatic identifying and so on.
However like this I display values to the user that he wouldn't really understand as the first record would for example be
CustId    Name    FirstName    Phone    FavColorId    LivingPlaceId
1            Me         Me Again     2211            1                    1

So when displaying the grid I would like FavColorId to be replaced with it's colorName with that Id. The same for livingPlace, I'd want the grid to show country for

example with that stored id.
For this example let's assume the values are stored in a List<FavoriteColors> and a List<LivingPlace>.

That's what I'm seeking to accomplish in a nutshell.
I was thinking of adding an unbound column for each id-field (in code) after setting the datasource to customers (haven't looked it up yet, but that should be possible right?), and afterward I'd go through the whole grid with a foreach(UltraGridRow in grid) loop, filling the unbound columns with the looked-up data.
And then I'd hide the columns that the user doesn't actually need to see.
However, I suppose that'll be rather performance ineffective, so was wondering what you folks think of this.

Ok, I think that's about it.