Probelm showing Manually Created BO in devexpress Grid


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I am having  a problem displaying fields in a Devex Grid. The only fields that will diplay, are the Original Fields from my Main Table BO

I want to select out different fields from a few joined Tables and display them in  Grid. For this purpose , I have set up a Dummy BO, with just two fields, and I use this as a sort of Repository to hold the fields I select out. So say my Dummy Table (And BuisnessObject) has just 2 fields D01_pk and D01_Val1.

The only purpose of the Dummy Table is to be able to join the fields and end up with one Table, but the only fields I can get to display are the fields from the original Source BO (In my case just 2 fields). All other fields just show blanks, even though the Business Object populated with the correct count of rows.

I have the following code in the Load of the form (I cannot assign the BBS to a business object on the form parameters as I have not yet created the BusinessObject, this is why I am setting the BusinessObject to the BBS in the Form Load)

Kernel_BOLibrary.XBO myBO = new XBO();        // My Dummy Business Object whcih I use to JOin other Tbales into
SqlCommand comm = new SqlCommand();
comm.CommandText = "Select 1 as D01_PK,'XXX' as D01_Val1,  MyField1,MyField2,MyField3 from TABL1 join TABL2 on X=Y ";
myBO.Clear();
myBO.FillDataTable(comm);
bbsPost.BusinessObject = myBO;
gridPost.DataSource = bbsPost;


So in the Grid, DO1_Pk and D01_Val1 display fine, but I cannot get the other fields, which I have joined (MyField1,MyField2,Myfield3) to display


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

This would be easier to understand if you can provide a quick sample to work with, but I will try to understand the problem...

Currently at design time, you mapped a BBS to the grid with a BO with fields D01_PK and D01_VAL1 correct?

Then when loading the form, you will load your  BO with original 2 fields above plus more columns MyField1, MyField2, etc. right?

If my assertion is correct, does your Kernel_BOLibrary.XBO has the extra field properties for MyField1, MyField2, etc. ?
if it does not, then that may be the problem, the DevExpress grid is binded to a BBS and this to a BO which does not have the columns as properties of the BO to show up in the grid.

Please let me know if I understand the issue before continue?

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy. Thanks for replying. Yes, you have the requirement spot on.

I just dropped a BBS onto the form, and did not map it to a BO, as I am creating the BO on the Load, to take in the additional fields. I am instantiating just a General Purpose Business Object, with 2 fields, so that I can use the BO.FillDataTable to 'Create' an entity which has fields from many tables. This is something I will need to do an awful lot, i.e. create an entity whcih has fields, other than are in any of the Business Objects (i.e. are the result of a Join from Many Tables)

I dont know any other way to do this other than , picking any Business Object (In my case I use a 'Dummy' Business Object with just two fields Wink and then using the MyBO.FillDataTable("Select and join a few Tables") to pouplulate the BO with 'ALL' the fields I require. I am happy that the BO is being correctly populated with all the fields ok, but then I need to display them in the Grid.

If this will not work, maybe there's a better/alternative way of doing it
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
You are welcome Ger.

First, let me explain how the BO works.  Basically the BO has a DataTable (DT), then when you use the Business Object Mapper (BOM) it will create custom field properties for each field in your table.

When you use any Fill method in your BO the internal data table will have all the fields included in the SELECT statement, but the BBS will only present the BO fields, so in your case, it will not show the fields in the DT. 
Since you will be using grid with generic fields (columns), then instead of using a BBS as the source of the grid, try using a data table and then assign the BO.CurrentDataTable as the source. 
I don't have any sample since all my DevExpress grid use the BBS with the correct fields, but it should work.

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy.

I changed datasource to a DataTable and it now displays fine... not sure though if I run up up and down the Grid , will I keep in sync with the BusinessObject ??

I am assuming that if I change anything in the grid though, that the underlying BO will also change(Yet to test)

Also, for any lurkers, initially I was not able to get some of the fields to display
In My Select statement, I had something like:  Select Field1,Field2,Filed3 from MyTable
In the DevExpress Columns, I had FIELD1, FIELD2, FIELD3...and nothing displayed, but when I changed the Case, everything worked fine, so even though in the Select, Case does not matter, in Populating the Grid Fields, the Field names MUST match with whats in the Select Statement..... no error is given , just the columns dont display

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
If you wrap your BO in a business binding source, then attach the grid to the business binding source, the records will be kept in sync when someone changes the row in the grid.  You can do a search out here on the forum for more information about the BusinessBindingSource, but this will be the ticket when dealing with a grid.
Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Gen,

So as you said, if by changing the casing of the field names in the grid, it will show the columns using a BBS, then use the BBS so it will give you the CurrentRowIndex sync with your BO, otherwise, if you have to go with the data table solution, you may need to do your own synchronization when moving up/down the grid.

Also, if your BO does not have the custom field properties for each table column, then you would have to access those using the BO's Items collection.

Edhy Rijo

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Trent. Thanks for replying.

My initial route was to go with the BBS, but I found that Selecting out and joining other tables and ending up with Columns in the Instantiated BO (that are not in the Original BO) meant that these columns were not visible in the Grid. This is the reason I went with the DataTable as the dataSource of the Devex Grid,, where I Could  see all the columns . Is this the expected behavior or am I doing something wrong  
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)Advanced StrataFrame User (654 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Edhy

.....So as you said, if by changing the casing of the field names in the grid, it will show the columns using a BBS, then use the BBS so it will give you the CurrentRowIndex sync with your BO


Sorry I gave the wrong impression.... still cant see the columns if coming from a BBS, but can see them if DataSource is a DataTbale, but with a DataTable, column names have to be the same case as the select statement

Regards,

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

No problem I understand now. 
Well, since your need is to have some sort of generic solution, if you want to have it all working together and look natural, you can do the following:
  1. Unless you are using SELECT * in your fill method.
  2. Create an SQL View with all the fields expected by the grid. 
  3. Create a BO and map it with BOM to the SQL Database View, this will give you the data schema expected.
  4. Add  a BBS and your BO to your form, assign the BO based on the view to the BBS and use the BBS as the grid source.  This will give you all the columns in your view where you can setup captions and other properties.
If you really don't know the column names of your SELECT statement, then you would need to go with the data table route and use code to loop through all the columns of the data table and create columns with captions.

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