Show lookup description data in a grid or listview


Author
Message
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
No problem.  You'll end up using those custom properties more than you think Wink
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Trent,

After a second thought, I decided to try Tim's suggestion to create a Custom Property and after reading Tim's great sample and with the SF help file, I could not believe how easy it was to have 2 Custom Field Properties to handle this situation and not have to add a single line of code at the form level, which keep the things simple.

For the sake of new SF users, here is the code for one of my Custom Field Properties:

''' <summary>

''' This property will return a formatted Building Address

''' </summary>

''' <remarks></remarks>

<Browsable(False), _

BusinessFieldDisplayInEditor(), _

Description("CustomerBuildingAddress"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public ReadOnly Property [CustomerBuildingAddress]() As System.String

     Get

          Dim loBusinessObject As New BuildingsBO

          loBusinessObject.FillByPrimaryKey(Me.FK_Buildings)

          If loBusinessObject.Count = 1 Then

               Return String.Format("{0}, {1} {2} {3}", loBusinessObject.Street, loBusinessObject.City, loBusinessObject.State, loBusinessObject.Zip)

          Else

               Return String.Empty

          End If

          ' Release the Business Object

          loBusinessObject.Dispose()

     End Get

End Property

Once again, big thanks to Tim and Trent for the lecture on how to accomplish this task. Hehe

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It sounds like you do not have the column setup as PopulatedThroughEvent.  Verify that and let me know.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,

Sorry about that, it was a copy/paste problem, here is the code:Cool

Private Sub ServiceCallsBO1_BrowseDialog_RowPopulating(ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs) Handles ServiceCallsBO1_BrowseDialog.RowPopulating

     '-- Get the Appliance Name using the FK_Appliances field value.

     With CType(e.BusinessObject, ATR_BO_Library.ServiceCallsAppliancesBO)

          Dim loAppliancesBO As New ATR_BO_Library.AppliancesBO

          e.Values(1).DisplayValue = loAppliancesBO.GetApplianceName(.FK_Appliances)

          '-- Clean Up the new Business Object

          loAppliancesBO.Dispose()

     End With

End Sub



Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Look real close at your code Wink

With CType(e.BusinessObject, ATR_BO_Library.ServiceCallsAppliancesBO)

          Dim loBO As New ATR_BO_Library.AppliancesBO

          e.Values(1).DisplayValue = loBO.GetApplianceName(.FK_Appliances)

     End With

Here is a tip...it isn't the Browse Dialog BigGrin


Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Trent,

In a Browser Dialog, I need also to show a descriptive field name and tried using the same code in the ServiceCallsBO1_BrowseDialog_RowPopulating, but it generates this error:

InvalidCastException
  Unable to cast object of type 'ATR_BO_Library.ServiceCallsBO' to type 'ATR_BO_Library.ServiceCallsAppliancesBO'.

Source     : ATR System

Stack Trace:
   at ATR_System.frmServiceCalls.ServiceCallsBO1_BrowseDialog_RowPopulating(RowPopulatingEventArgs e) in E:\Visual Studio 2005\StrataFrame Projects\ATR Systems\ATR System with not security\ATR System\Forms\frmServiceCalls.vb:line 235
   at MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogwindow.CreateListViewItem()
   at MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogwindow.LoadBrowseResults()
   at MicroFour.StrataFrame.UI.Windows.Forms.BrowseDialogwindow.ExecuteSearch()
   at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Here is the code in ServiceCallsBO1_BrowseDialog_RowPopulating:

 

     With CType(e.BusinessObject, ATR_BO_Library.ServiceCallsAppliancesBO)

          Dim loBO As New ATR_BO_Library.AppliancesBO

          e.Values(1).DisplayValue = loBO.GetApplianceName(.FK_Appliances)

     End With

What is wrong with this approach in the Browser Dialog?



Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent L. Taylor (11/07/2007)

I don't know if you knew this, but you can create a parameter and provide the value all in one statement:

command.Parameters.AddWithValue("@myParm",MyValue).SqlDbType = SqlDbType.VarChar

It is a handy little trick BigGrin

Hi Trent,

Thanks again, for checking the code.  And please do not assume what I would know for know, since I am learning VB.NET, SF, SQL2005 and more at the same time, so there are many things I don't know or fully understand yet. Wink

I replaced the two command lines with the single one and it is much cleaner.  I also kind a like the Scalar methods now that I know they exist BigGrin

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
It looks good.  It depends on what I am trying to accomplish, but I use a lot of scalar methods for this type of thing since there is little overhead.  However, if there could be a lot of records coming back, then it is usually a good idea to make sure it is included in the query somehow.  But you code looks good Smile

I don't know if you knew this, but you can create a parameter and provide the value all in one statement:

command.Parameters.AddWithValue("@myParm",MyValue).SqlDbType = SqlDbType.VarChar

It is a handy little trick BigGrin

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,

For testing purpose in order to see which method will fit better to me, I started with an Scalar method as follow:

''' <summary>

''' Get the Appliance Name using the FK_Appliances field value.

''' </summary>

''' <param name="e"></param>

''' <remarks></remarks>

Private Sub lvAppliances_RowPopulating(ByVal e As MicroFour.StrataFrame.UI.Windows.Forms.RowPopulatingEventArgs) Handles lvAppliances.RowPopulating

     With CType(e.BusinessObject, ATR_BO_Library.ServiceCallsAppliancesBO)

          Dim loBO As New ATR_BO_Library.AppliancesBO

          e.Values(1).DisplayValue = loBO.GetApplianceName(.FK_Appliances)

     End With

End Sub

Some things are different from Trent's post, like e.Column() which does not exist, so I tested e.Values() and that worked just fine! and in the CType() I needed to make reference to a new strong type BO class ATR_BO_Library.ServiceCallsAppliancesBO which is not the way in Trent's post.

So far, I think that an Scalar method will make sense for me because the code will be in the BO class, so I can reuse it all the time, and it was pretty simple to implement.

Here is the Scalar method code:

''' <summary>

''' Get the correct Appliance Name via the PK_Appliances field

''' </summary>

''' <param name="AppliancePrimaryKey"></param>

''' <returns>

''' The Appliance Name as string

''' </returns>

''' <remarks></remarks>

Public Function GetApplianceName(ByVal AppliancePrimaryKey As Integer) As String

     '-- Establish Locals

     Dim loCommand As New SqlCommand()

     '-- Build the command

     loCommand.CommandText = "SELECT ApplianceName FROM Appliances WHERE PK_Appliances = @Appliances_PK"

     '-- Create and set the parameters

     loCommand.Parameters.Add("@Appliances_PK", SqlDbType.Int)

     loCommand.Parameters("@Appliances_PK").Value = AppliancePrimaryKey

     '-- Execute the query and return the value

     Return CType(Me.ExecuteScalar(loCommand), String)

End Function

Later on I will try Tim's way using a custom field property.

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Tim, Trent,

Thanks for the ideas, I will play with them now and post result in a bit.BigGrin

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search