Business Binding Source is one record behind select grid row


Author
Message
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi there,

I have encountered a problem which goes like this:

I put a BO (customers from the sample-db) on a form. Add a Business Binding Source which is connected to the BO. Then I add a grid whose datasource is the BBS. Now I want to test a little row/cell-formatting depending on different values on the database. The first step was to show one field (Last Name) in a correponding textbox. I wrote this code



Private Sub DataGridView1_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter

TextBox1.Text = BBS.BusinessObject.Item(
"cust_lastname")

End Sub



But this does not work. The textbox is always one record behind. For example.

It starts with "Achong". I skip down one record down to "Abel", the textbox still shows "Achong". I skip to the next record "Smith", the textbox now show "Abel". So it seems that the BBS is one record behind the selected row on the grid.

Did I miss something there? If I try this with a dataset bound to the grid, it works correct.

Best regards

Thomas
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 Thomas,

The BBS should be moving the record pointer of the BO automatically, all you need to do is to put your code in the BO.Navigated() event and reference the BO.FieldProperty instead of the BO.Item()
TextBox1.Text = Me.BusinessObject1.cust_lastname


Edhy Rijo

Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Edhy,

thanks for the tip but the behaviour did not change. But I found some hints on the net showing me, that teh rowenter-event is not appropriate for this task and now I determine the rfow-change this way:



Private nRow as integer = 0

Private Sub DataGridView1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellChanged

If DataGridView1.CurrentCell.RowIndex <> nRow Then

TextBox1.Text = BBS.BusinessObject.Item("cust_lastname")

nRow = DataGridView1.CurrentCell.RowIndex

End If

End sub



As this does not affect when loading the form I "take" the first row of the grid manually in the form load event.

In comparison to the good old VFP afterrowcolchange-event this seem to be complicated and if someone has a hint how this could be done easier/more elegant I would really appreciate that.

Best regards

Thomas
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 Thomas,

Well, in reality it is very simple, but you need to know how StrataFrame works in order to take advantage of it and as I always say we need to work with the framework not against it.
Since you are new to SF, I put together a quick and dirty sample that will show you a DataGrid binded to a SF BBS with a customer business object.
Pay attention to the control classes used.  All controls except the DataGridView are from the StrataFrame toolbox.  Notice how the First and Last name textboxes are binded to the SF business object bizCustomers1.
The only code in the form is to load the customers data into the business object, the rest is handle by the SF BBS which synchronize the row index with the bo.CurrentRowIndex, so if you need to handle that you can use the bo.Navigated and always make reference to the BO.FieldName instead of the grid's row.

Enjoy!!!

P.S.
Review the SF help file several times.  Long ago I took a SF training in Amarillo Texas, and they provided a very good and complete handbook which I believe they should make it available to new users since it has more detail and completed explanations that will complement the help file.  Ask them if they can provide you with the electronic version of that handbook.

Edhy Rijo

Attachments
DataGridSample.zip (100 views, 116.00 KB)
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Edhy,

thanks a lot for all these useful hints and the sample program. I will immediately have a look on it.

Best regards

Thomas
Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Edhy,

I checked your sample and everything there is clear and understandable. Maybe my starting point was a bit confusing because my aim was not to show a field via a datagridview-event in another control (like the textbox) but to understand how and where I can access data within grid-events. If I want, for example, change a cell-background-color, I have to do this within grid-events or is there another, better way?

Best regards

Thomas
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
Thomas Holste (9/16/2011)
If I want, for example, change a cell-background-color, I have to do this within grid-events or is there another, better way?

Well you that will depend on the condition used to change the cell background, if you want to change this during the grid being populated, then yes, you have to look for an event that will trigger during that time, or if you want the change to happen after data has been loaded in the grid in another condition, then you will need to know the cell and row to make the change.

I personally don't use the plain DataGridView, I use the DevExpress controls and they are just fantastic, lot of flexibility to handle all kind of condition at the grid level and most of them with not coding just setting the right properties.  I started using DevExpress controls no long ago, but after testing the grid and replacing some SF Listview and getting the complements from users finding this grid much user friendly and advance than the SF ListView, I am now replacing all SF ListView with the DevExpress grid control.

Edhy Rijo

Thomas Holste
Thomas Holste
StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)StrataFrame User (360 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Edhy,

that is good news as I have just downloaded a trial version of the devexpress-grid. My VFP-Apps which I will replace over the next years with VS/SQL/Strataframe-Apps are very much grid-centric and in some cases I need an editable grid. So to read your enthuasiasm about about the devexpress-controls makes me feel right about this way. Thanks lot for your help.

Best regards

Thomas
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
You are welcome Thomas, and keep us posted with your improvement on DevExpress controls, there are couple of other SF developers which also use DevExpress.  StrataFrame provides an wrapper class for the most common used DevExpress control which add SF binding and make it easier to work with them.

I moved from VFP and Visual ProMatrix framework couple of years ago, and it was a painful transition since I did not knew anything about .Net and very littler about SQL, so it took many hours of hard dedication and focus on looking forward and not thinking the VFP way.  I review 2 major frameworks, Ideablade and StrataFrame and once decided on StrataFrame, I closed all other framework, tools and VFP mentality and it has been very worthy.  StrataFrame business objects are very, very powerful and flexible, much more than working with VFP aliases you can create them via code to manipulate your data in any possible way, for me, very impressive approach by the SF team.

Again, review all documentation several times, search the forums, there are tons of code samples and the chances that whatever problem you encounter could has been fixed before.  Good luck and welcome to the party w00t

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