Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Dynamically Adding Cells to TDataSet and TGrid
Tue, Nov 7 2017 1:14 PMPermanent Link

erickengelke

I have to support a varying number of cells.

So I am loading a TDataSetLabels which has the human names and UIDs of what will be columns
to load into a grid.  And then I will load the new TDataSet1 with those UIDs into the Grid's data.


procedure TFormILOCourse.ScrollPanel1Show(Sender: TObject);
var
 c : TDataColumn;
 gc : TGridColumn;
 i : integer;
begin
 LoadLabels;
 
 DataSetLabels.Open;
 DataSetLabels.First;
 while not DataSetLabels.EOF do begin
    //
    c := DataSet1.Columns.Add;
    c.DataType := dtBoolean;
    c.Name := 'UID'+DataSetLabels.Columns.Column['uid'].AsString;

    gc := grid1.NewColumn;
    grid1.MakeColumnVisible( gc );
    gc.Name := 'Col'+c.Name;
    gc.ControlType := ctCheckBox;

 /// Fails at next line
    gc.DataColumn := c.Name;
    
    gc.Width := 60;

    gc.Tag := DataSetLabels.Columns.Column['uid'].AsInteger;
    gc.Hint := DataSetLabels.Columns.Column['desc'].AsString;
    gc.Header.Caption := DataSetLabels.Columns.Column['short'].AsString;
    gc.Header.Wrap := True;

    DataSetLabels.Next;
 end;

 DataSet1.Open;
 DataSet1.LoadRows('{"rows":[
{  "UID1":True, "UID2":False,"UID3":True,"UID4":True,"UID5":True,"UID6":True,"UID7":True,"UID8":True,"UID9":True,"UID10":True,
 "UID11":True,

The code works fine until I add the line: gc.DataColumn := c.Name;
Then I get the error: List Index 6 out of bounds
The first new column will be column 6.  What am I missing.

Thanks
http://www.erickengelke.com
Tue, Nov 7 2017 1:22 PMPermanent Link

erickengelke

erickengelke wrote:


> I have to support a varying number of cells.

I found a solution.  I can set the column's data field if I use async to postpone the assignment.

Erick
http://www.erickengelke.com
Wed, Nov 8 2017 10:59 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Erick,

<< I found a solution.  I can set the column's data field if I use async to postpone the assignment. >>

I would be careful with that type of workaround.  It may end up breaking, depending upon what is in the UI message queue in the browser.

Is the LoadLabels method loading the DataSetLabels dataset ?  If so, then you should put the rest of the code in a separate procedure that you can call from the AfterLoad event for the DataSetLabels dataset.

In general, you're going to need to chain the AfterLoad event handlers so that you can ensure that *both* datasets are loaded before you do anything with them.

EWB actually needs an async "load these multiple datasets" call, but doesn't have one yet, so chaining the event handlers is what you've got to work with.

Tim Young
Elevate Software
www.elevatesoft.com
Fri, Nov 10 2017 6:40 PMPermanent Link

KimHJ

Comca Systems, Inc

Tim Young [Elevate Software] wrote:

>>In general, you're going to need to chain the AfterLoad event handlers so that you can ensure that *both* datasets are loaded before you do anything with them.<<

I have the same problem I'm loading Customer rows and Invoice rows and most of the time if I create the list in AfterLoad of customer I'm missing Invoices. Do you have any example?

Thanks.
Kim
Sat, Nov 11 2017 4:25 AMPermanent Link

Uli Becker

Kim,
 
> I have the same problem I'm loading Customer rows and Invoice rows and most of the time if I create the list in AfterLoad of customer I'm missing Invoices. Do you have any example?
Tim already gave you the answer:

<<
EWB actually needs an async "load these multiple datasets" call, but doesn't have one yet, so chaining the event handlers is what you've got to work with.
>>

In your case that means:

Use the Customer AfterLoad event to load the Invoices dataset. Only in the Invoices AfterLoad event populate the grid.
That makes sure that both datasets have been loaded before the grid is populated.

Uli
Mon, Nov 27 2017 8:26 PMPermanent Link

KimHJ

Comca Systems, Inc

Uli Becker wrote:

>>In your case that means:

Use the Customer AfterLoad event to load the Invoices dataset. Only in the Invoices AfterLoad event populate the grid.
That makes sure that both datasets have been loaded before the grid is populated.<<

Thanks Uli, I don't know why I didn't think of that.
Kim
Image