I have a Customer CSLA Business Object that contains a Customer Name, and a Customer Id. I'd like to be able bind both fields to a single ComboBox with the format "Customer Name - Customer Id" and I'm having some troubles. I can add a new property to the Customer Business object that does this for me, but I doesn't really belong there.
I'm using .Net 2008 and was wondering if there was a possiblity of using Method Extensions. Created one, but it is a method, and I can't data bind to a method. Is there anyway to make an Property Extension? I'm I missing something painfully obvious?
Is the BO you are talking about a Name-Value List? That is the CSLA class designed specifically for binding to ListBox style controls.
Why not just override the ToString() function to return the string in a format you want?
Regards;
/jb
in reality you can, this is an exampe:
Public
Class BusinessObject Public Overrides Function ToString() As String Return "ToString" End FunctionEnd
ClassPublic
Class BusinessObjectsList Inherits System.ComponentModel.BindingList(Of BusinessObject)End
ClassPublic
Class Form1 Private list As New BusinessObjectsList Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadlist.Add(
New BusinessObject)list.Add(
New BusinessObject)BusinessObjectsListBindingSource.DataSource = list
End SubEnd
Classyou must add a Combobox to your form and bind it to BusinessObjectList (by creating a new object data source from the Data sources pane.
now when you run the application, you will notice that the combobox is filled with 2 objects named ToString :)
I think that is about as close as I can come given my current setup. Thanks.
So I would suggest that the Use Case you have here is for a specific "user-friendly" string in a ListBox for a specific UI requirement.
It's a different BO to the other one.
Use the NVL class, or something similar.
dlabar:I'm currently Using Forms. There is nothing keeping me from switching to WPF. Is that a major jump?
It is a huge jump. If your applicaiton is already using Forms, I wouldn't make the jump. If you are just starting out and have some extra time(a lot of extra time) for the learning curve, it might be worth it. In either case, I echo the other comments to this post of creating an nvl object for this use case. You would generally use the nvl in WPF as well as it is more light weight.
Copyright (c) Marimer LLC