11/29/2024 6:28:08 PM
|
|
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!
Forum to discuss usage & tips for SalesLogix controls and other 3rd party ActiveX controls. View the code of conduct for posting guidelines.
|
|
|
|
How to Populate SLX grid Programmatically
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
|
|
|
|
Re: How to Populate SLX grid Programmatically
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. |
|
|
|
Re: How to Populate SLX grid Programmatically
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 |
|
|
|
Re: How to Populate SLX grid Programmatically
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. |
|
|
|
Re: How to Populate SLX grid Programmatically
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 |
|
|
| |
|
Re: How to Populate SLX grid Programmatically
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? |
|
|
|
Re: How to Populate SLX grid Programmatically
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.
|
|
|
| |
|
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!
|
|
|
|
|
|
|
|