By Ger Cannoll - 7/18/2011
I have a grid that is using a BusinessBindingSource. Works fine if I am taking all fields from the standard BO. I want to add one extra field, which is taken from another table , so I have changed my select statement whcih popualates the BO, to do a join to the lookup table
myGrid.DataSource = this.businessBindingSource1; myBO1.FillDataTable("SELECT * FROM SCP JOIN KMA ON SCP_STKREF = KMA_STKREF"); (The Table SCP is the BO source in the Business Object mapper. I use the join just to get one lookup field)
In the Grid however, I still dont see the Description Field (Which comes from the Joined KMA table)
Other than the above, I have not made any changes to the BO.
Do I need to 'add' the extra field as a custom field in the BO ? If so, is there any C# code around that does this
|
By Edhy Rijo - 7/18/2011
Gerard O Carroll (7/18/2011) Do I need to 'add' the extra field as a custom field in the BO ? If so, is there any C# code around that does this Hi Gerard,
You can either create a view in your database with your join table and use this view for the BO, this way the description field will be there.
Or you can keep using what you have now and simply add a Custom Field Property to the BO with the same name as the field in the JOIN that you want to show, of course this should be a ReadOnly property and you must override the GetCustomBindablePropertyDescriptors so you new custom field property will show up in the type editors. I use this method 99% of the time to avoid having to create a view and to keep things in the BO instead of having dependencies all over the project. Also the beauty of this is that the BO.CurrentDataTable will have all the columns specified in the SELECT statement, but if it does not find a property that match their names you will not be able to access it via the property, even though you could access it via the BO.CurrentRow.Item("ColumnName"). See the BO.Designer file to see how it is created by the BOM.
Here is a sample code: [code]
protected override FieldPropertyDescriptor[] GetCustomBindablePropertyDescriptors() { // Create and return a new array of FieldPropertyDescriptor objects that contains // the ReflectionPropertyDescriptor for the Custom Fields. return new FieldPropertyDescriptor[] { new ReflectionPropertyDescriptor("ServiceName", typeof(bizApptServices)) }; }
[Browsable(false), BusinessFieldDisplayInEditor(), Description("Service Name"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public System.String ServiceName { get { return Convert.ToString(this.CurrentRow.Item("ServiceName")); } }[/codes]
P.S. The above code was converted from VB.NET to C# using http://www.developerfusion.com/tools/convert/vb-to-csharp/
|
By Ger Cannoll - 7/18/2011
Hi Edhy
Many thanks for your reply and very detailed explanation. I have the grid displaying the 'Lookup' description now as a result of setting up the 'Cutom Fields'
One other thing it would be nice to do, is to show the description as one of the fields (My Form has a Grid on the LHS and as I navigate through the grid, the Fields from the BO I want to edit are dislayed on the RHS as individual fields , and change as I navigate through the grid.)
When I include the description field as one of the Fields (read only) (it is now appearing as one of the BO Fields ) , I get an error saying the Description Field does not belong to the Table (from whcih the BO is derived)
This would be nice to have, but is not a show stopper as I can display it using some code . (Also if I am adding a new row, I will need to code for it anyway)
|
By Edhy Rijo - 7/18/2011
I understand. The problem is that you are using a DataGridView and the Description field in the grid may not be ReadOnly even though its BO Custom Field Property is ReadOnly, you may need to set this column as Read Only. I don't use grids in my applications, I found easier to use a the SF listview or the new StrataListView which is more powerful and fast.
Of course you may have your reasons to use a grid, but anyway if you are showing a description field from a Join table, then you should not be able to modify the description, instead change its FK value or better yet use a combobox control to show the description from its FK value.
I tend to have my tables normalized and rely on SQL statements with join conditions to get descriptions and custom field properties to take advantage of setting those in SF controls and reports. This is a feature I constantly use in all my SF applications.
Any particular reason why you are using a grid instead of one of the SF listviews?
|
By Ger Cannoll - 7/18/2011
Hi Edhy.
I would also normally use a Combo or similar for descriptions, but in that the 'Custom Field' now apperas to be part of the BO, and also because it was showing on the grid, I thought it would be nice just to 'Drop' it on the Field section of the form, and set its datasource to the field.
Regarding Grids, in all my apps I have always used grids and found them to be very flexible. On Dot Net apps, I have more or less standardised on the Deveexpress ultra grid and up to now have used it in all forms. I have also data enabled all the fields (i.e. they are taken from a Table of Fields ) rather than hardcoded onto each form. As the app goes out to lots of different types of customers, having a facility for each customer to be able to decide on 'their' own fields was a must. There is also a facility in ultragrid to save a specific users 'Grid' settings and 'restore' them next time in (have not used this yet). Its also quite easy to 'print' contents of a grid. I also found the sorting, selecting, subtotalling , grouping, searching on the devex ultra grid to be quite easy to implement and very powerful. I had initially looked at the Browse Dialog to do the same thing but it seemed to be a littlle bit more difficult to implement what I wanted to do. I probably did not give the ListView much attention as it is a 'readonly' control. Most of my grids are also read only, but there are also a substantial no that will be editiable with just a few columns , and I wanted a consistent look across the whole app.
|
By Edhy Rijo - 7/19/2011
Hi Gerard,
Well there is a huge difference between DevExpress Ultra Grid and the DataGridView, so now I understand why you prefer grids and I agree with you.
|
|