Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Tuesday, November 26, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 Architect Forums - Controls
Forum to discuss usage & tips for SalesLogix controls and other 3rd party ActiveX controls. View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to Controls | New ThreadView:  Search:  
 Author  Thread: How to Populate SLX grid Programmatically
Jordan
Posts: 61
 
How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 26 Oct 09 11:08 AM
I will appreciate it if someone could give me an advice about the following reqirement:

In our project, the data come from both SLX and the other external databases and have many calulation columns, those data can’t be loaded into one recordset but all of data have to be displayed on one Grid. So we need to populate the SLX grid programmatically.

We have populated the columns of the Grid and got the RecordSets successfully. What we need to do is to populate the the Grid programmatically. Simply to say by using an simplified example, we want to know the syntex about how to set a value to the column of the Grid.

For a Grid and a RecordSet:

if (not objRS.EOF and not objRS.BOF) then
do while not EOF

‘Add Data to the Datagrid here based on the RecordSet
Grid.xxxx.xxxx = objRS(“xxxx”)

objRS.MoveNext
loop
end if

By the way, our system is SLX Lan 7.0.1

Thanks in advance
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 27 Oct 09 1:24 AM
Quick question:
- Are you able to assemble the data on an SQL View? If so, create your SQL view, then enable it on SLX and bind it to the Grid.

Now to your issue, if you have built the Grid properly, and just want to bind to a Recordset:
Grid.Recordset = objRS

Now, I am confused by this statement: "we want to know the syntex about how to set a value to the column of the Grid."
If you have defined the grid Columns correctly, then just need to attach the Recordset to the Grid as shown above.
Otherwise, you may want to clear the Grid's Columns and create then programatically.
[Reply][Quote]
Jordan
Posts: 61
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 28 Oct 09 10:33 AM
If the data which we need can be queried out by one SQL statement, then we can set/bind the SQL statement/recordset to the grid directly. But, in our project, the data come from different queries which can’t be joined in logic BUT some values need to be displayed on one grid. So, we need to loop the grid programmatically based on the primary recordset. To simplify the question, I provide a pseudo code as below. As long as we can realize the line ***, we will be able to get our project successfully. Is it possible?

BWT, the grid has existed and its columns has been populated and we have got the recordsets.

if (not objRS.EOF and not objRS.BOF) then

do while not EOF

‘Add Data to the Datagrid here based on the RecordSet
*** Grid.xxxx.xxxx = objRS(“xxxx”)

objRS.MoveNext

loop

end if

Thanks
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 28 Oct 09 10:54 AM
Seems to me as if you are looking into building Possibly the Grid and the Recordset dynamically.

You could always do something as follows:

- Create Recordset Object (to be bound to Datagrid):
On it don't load data from Database, but define its columns programatically.

- Read all your Recordsets
Loop through your primary recordsets, while doing so, read your additional recordsets, then write data into the Custom Recordset

Bind your grid to your Custom Recordset.


There are several grids in SLX on which their columns are created programatically. If you look into the Add Opportunity Product functionality, you will notice how it uses multiple recordsets to keep track of the Status of Rows, build the Columns programatically, passes recordsets across views, etc. That may be a good example for you to look into.

Bottom line is that you should be able to build your Own Dataset programatically, Define the Columns on your grid programatically as well, and then bind that recordset to that grid.
[Reply][Quote]
Jordan
Posts: 61
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 29 Oct 09 4:04 PM
Thanks Raul.

This approach is pretty good. We are heading for it.

For this approach, finally, we will bind one recordset to one grid. But we are experiencing a binding issue for now. In my opinion, the successful binding will be the basis of the bound approach. Only after getting it, then we will be able to move ahead.

To simplify the question/issue, let me provide a simple example which you also can reproduce (Our system is SLX Lan 7.0.1).

On a manage form, there is a Datagrid “grdSearchedResult” and a Button “btnSubmit”. The following is the code of the form:

==========

Option Explicit

Sub AXFormOpen(Sender)

Dim colAccount, colAccountID

Set colAccount = grdSearchedResult.Columns.Add(0) ' 0 - Standard
colAccount.FieldName = "ACCOUNT"
colAccount.Caption = "Account"
colAccount.Width = 100

Set colAccountID = grdSearchedResult.Columns.Add(0) ' 0 - Standard
colAccountID.FieldName = "ACCOUNTID"
colAccountID.Caption = "AccountID"
colAccountID.Width = 50
colAccountID.Visible = False

End Sub


Sub btnSubmitClick(Sender)

Dim objConn
Dim objRS
Dim strSQL

grdSearchedResult.SQL.Text = ""
Set grdSearchedResult.Recordset = Nothing
grdSearchedResult.Refresh

strSQL = "SELECT TOP 10 ACCOUNT, ACCOUNTID FROM ACCOUNT"

Set objConn = CreateObject("ADODB.Connection")
objConn.Open(Application.ConnectionString)

Set objRS = CreateObject("ADODB.Recordset")
objRS.CursorLocation = adUseClient
objRS.CursorType = adOpenStatic
objRS.LockType = adLockOptimistic

objRS.Open strSQL, objConn

Set grdSearchedResult.Recordset = objRS
grdSearchedResult.Refresh

objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing

End Sub

==========

Whenever clicking the button, I got the error message:

"Operation is not allowed when the object is closed."

Any thoughts?

Thanks again
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 09 9:14 AM
Yes, do not close the recordset.

If you want to, you could disconnect it, but don't close it.
[Reply][Quote]
Jordan
Posts: 61
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 09 11:07 AM
Thanks Raul.

After I commented out the objRS.Close and objConn.Close like:

'objRS.Close
'objConn.Close
Set objRS = Nothing
Set objConn = Nothing
Set objSLXDB = Nothing,

the error massage was gone. So good!

But if we don't close the objConn, then the system-level resource won't be released, right? If so, it will probably hurt the performane of the whole system, right?

What do you mean by "If you want to, you could disconnect it, but don't close it."? Could you give me a further advice about how to disconnect objConn and/or objRS?
[Reply][Quote]
Raul A. Chavez
Posts: 1300
Top 10 forum poster: 1300 posts
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 09 11:41 AM
You can google for ADODB Disconnected Recordset.

Basically, depending on how you setup your recordset (Cursor Type, Lock Type and Location) you could disconnect it from the connection:
>> objRS.Connection = nothing
Then you can close the Connection
>> objConn.Close

If later on you need to push the changes from that recordset into the DB, you would reopen the connection, reconnect the recordset and update it in batch mode.
[Reply][Quote]
Jordan
Posts: 61
 
Re: How to Populate SLX grid ProgrammaticallyYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 30 Oct 09 1:14 PM
It works. We can move ahead.

Thanks Raul so much.
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/26/2024 9:35:05 AM