By Charles Thomas Blankenship - 9/19/2013
Currently I'm using a DevExpress grid with the Business Binding Source and it is working swimmingly ... except for one thing.
I can only use the actual fields defined in the table to bind to the grid. I was hoping to be able to create a custom property and select that as the binding field for the column in the grid but that doesn't work. Here is an illustration:
I have a table named Lead and that table is loosely associated with another table named DialRecalls. I then created a stored procedure and linked these two tables together like so:
SELECT lea_id, lea_FirstName, lea_LastName, lea_SortName, lea_Address, lea_City, lea_ST, lea_ZipCode, lea_Phone, lea_Phone2, lea_SourceID, SPACE(50) AS lea_Source, lea_RegionID, SPACE(10) AS lea_Region, lea_TelemarketerID, SPACE(3) AS lea_TelemarketerName, dir_UserID AS lea_RecallUserID, SPACE(3) AS lea_RecallUserName, dir_RecallOn AS lea_RecallOn FROM Lead INNER JOIN DialRecalls ON lea_id = dir_lea_id WHERE lea_Status = 'L' AND dir_Active = 1 AND (dir_RecallOn >= @DateFrom AND dir_RecallOn <= @DateTo) AND dir_UserID = COALESCE(@dir_UserID, dir_UserID) AND lea_ST LIKE COALESCE(@lea_ST, lea_ST) + '%' AND lea_City LIKE COALESCE(@lea_City, lea_City) + '%' AND lea_ZipCode LIKE COALESCE(@lea_ZipCode, lea_ZipCode) + '%' AND lea_Phone LIKE COALESCE(@lea_Phone, lea_Phone) + '%' AND lea_SourceID IN (SELECT cos_ID FROM @SourceIDs) AND lea_RegionID IN (SELECT cor_ID FROM Contact_Regions WHERE cor_Region IN (SELECT cor_Region FROM @Regions)) ORDER BY dir_RecallOn
I then used that stored procedure in the FillByStoredProcedure method and populated the business object with the addition fields that I needed to display (performed using the AS function in SQL) ... as you can see one of those fields is lea_RecallOn which actually came from the DialRecall.dir_RecallOn field.
Next, I created a custom property on the business object like so
[Browsable(false), BusinessFieldDisplayInEditor(), Description("DialRecalls.dir_RecallOn"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public DateTime lea_RecallOn { get { return (DateTime)this.CurrentRow["lea_RecallOn"]; }
set { this.CurrentRow["lea_RecallOn"] = value; }
}
And finally, I went into the grid designer, created a new column, and bound it to the "lea_RecallOn" field. The problem is that the grid does not recognize any field that is not part of the strong typed data table created with the BO Mapper.
So, is there anyway to create a property that the grid can see without created a fake property in the DDT and building with the BO Mapper?
I did get around this by creating a lea_RecallOn column in the datatable and running the above stored procedure ... the grid then picked up the date which originated in the DialRecall table. I then excluded the field from the Insert and Update operations using the business object properties.
Any recommendations?
C. T.
|
By Ivan George Borges - 9/19/2013
Hi Charles.
See if this one helps:
http://forum.strataframe.net/FindPost17401.aspx
Boa noite.
|
By Charles Thomas Blankenship - 9/19/2013
After pounding my head on the desk for a while ... I went down and watched Hardball with Chris Matthews ... and came up with this.
There does not seem to be a performance hit with this solution and it does exactly what I want it to ... I just thought the BBS would be a bit more straight forward.
The problem it seems is that DevExpress XtraGrid does not care about custom properties ... they don't show up in the designer when populating the grid either ... which is a clue.
This solution takes the lea_id out of the grid, which comes directly from the table and uses that to seek to the primary key of the business object and then pluck the value out of the custom property and push it into the unbound column.
private void grvLeads_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e) { ColumnView view = sender as ColumnView;
if (e.Column.FieldName == "lea_Phone") { string phone = (string)view.GetRowCellValue(e.RowHandle, view.Columns["lea_Phone"]); e.DisplayText = string.Format("{0###) ###-####}", Convert.ToDouble(phone)); }
if (e.Column.FieldName == "lea_RecallOn") { int leadID = (int)view.GetRowCellValue(e.RowHandle, view.Columns["lea_id"]); oLead.SeekToPrimaryKey(leadID); e.DisplayText = string.Format("{0:d}",oLead.lea_RecallOn); } }
|
By StrataFrame Team - 9/20/2013
Howdy CT,
The post that Ivan gave is the way it's designed to work. We implement the ICustomTypeDescriptor interface on BusinessLayer in order to filter out the properties that most people don't need to look at on the business object. Properties like CurrentRow, CurrentDataTable, IsDirty, Count, etc. would show up in the grid if we didn't filter down to only the properties that are mapped. If you add a custom property to your business object, you need to add your property to the list of properties that are exposed for binding, otherwise, it gets filtered out with all of the other properties that are not "mapped" properties. The way to do this is to override the GetCustomBindablePropertyDescriptors and return a property descriptor for your custom property. The ReflectionPropertyDescriptor was created to be the easiest way to do it. Like this: Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor() '-- Create and return a new array of FieldPropertyDescriptor ' objects that contains the ReflectionPropertyDescriptor ' for the custom field. Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _ New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("myFieldProperty", GetType(MyBO))} End FunctionI hope this helps the next time you need to bind a custom property to a grid (or TextBox or anything else).
|
By Edhy Rijo - 9/20/2013
Hi Charles,
I was working outside yesterday and did not see your post until now. I also use DevExpress grids a lot and with several Custom Field Properties (which is one of the most useful features of the SF BO).
Follow Ben's recommendation overriding the GetCustomBindablePropertyDescriptors() and you should be good to go.
|
By Charles Thomas Blankenship - 9/21/2013
Well ... I hate to be dense in public but would one of you please speak C#? Here is my custom property ...
[Browsable(false), BusinessFieldDisplayInEditor(), Description("DialRecalls.dir_RecallOn"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public DateTime lea_RecallOn { get { return (DateTime)this.CurrentRow["lea_RecallOn"]; }
set { this.CurrentRow["lea_RecallOn"] = value; }
}
|
By Charles Thomas Blankenship - 9/21/2013
This mebbe?
protected override FieldPropertyDescriptor[] GetCustomBindablePropertyDescriptors() { FieldPropertyDescriptor[] fpd = {new ReflectionPropertyDescriptor("lea_RecallOn", typeof(Lead))}; return fpd; }
|
By Charles Thomas Blankenship - 9/21/2013
Yep ... that worked ... it is a good thing this is not 1692 in Winston, Salem ... if it were I'd have all of you burned as witches ... as this worked like magic.
|
By Charles Thomas Blankenship - 9/22/2013
Well, I knock down on weed and another one grows in its place ... the reason I wanted to perform an ID lookup after the initial join was to prevent the slowdown of the query just for looking up the name of the Telemarketer. So, I created a custom property, gave it a descriptor and bound that column to the XtraGrid. The data shows up without incident.
However ...
since I'm placing a value into one of the fields of the business object the business object is now "dirty" and it screws up the maintenance form toolbar button states.
Furthermore, each time the Undo button is pressed all of the Telemarketer names are erased from the column as they are in effect, changes to be rejected from the table.
How does one go about resetting the editing status of that particular field ... or ... keep it from registering a dirty business object altogether.
Thanks,
|
By Ivan George Borges - 9/23/2013
YourBO.CurrentDatatable.AcceptChanges()
|
By StrataFrame Team - 9/23/2013
Yep, Ivan nailed it. There's
bo.CurrentDataTable.AcceptChanges(); and bo.CurrentRow.AcceptChanges(); Whichever one you need. They both accept the edited values of the ADO.NET object as original values. FYI, this is the same thing we call on each row after it gets updated back to the database.
|
By Charles Thomas Blankenship - 9/24/2013
Hey ... who told you and didn't tell me ... once again I worship at the alter of the StrataFrame Gods.
You know what pisses me off ... I mean really pisses me off ... why does a sh*t product like DNN eclipse our user base in terms of seats ... I just don't freakin' get it.
|
|