Mega Search
23.2 Million


Sign Up

Make a donation  
IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb

I've just started working with  IWGrid and thought I'd be able to make selection panels with it (as I currently do with DBGrid in vcl).

I want to be able select a row, preferably by doubleclick (but also by selecting a row, then pressing a button).  I need to return info about the row.  I'd love to have it make the dataset record current then let me proceed from there but, if unable, maybe return info from the row's columns.

Apparently that's not a capability of IWDBGrid?

Google is my friend, and I see there are a number of other folks asking similar questions but I have failed to find an example showing this.  

How do I do this?  
Do I need to figure out some other way to select among records of a dataset?  If so, how are others doing it?   This problem must have been solved many times before.

Thanks,
Dan

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 21-Jan-2015, at 3:09 PM EST
From: Dan Barclay
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Alexandre Machado wrote:}{quote}
> > {quote:title=Dan Barclay wrote:}{quote}
> > > {quote:title=Alexandre Machado wrote:}{quote}
> > > > {quote:title=Dan Barclay wrote:}{quote}
> > > > Bug in IWDBGrid or IWRadioButton?  Or did I miss something?
> > > 
> > > I'll try to reproduce and let you know, OK?
> > Maybe you can answer another question while you're looking at that.
> > 
> > When I add the check/radio control to the row I create it as shown in the code above.
> > 
> > I have found that anytime the grid is refreshed (change query for example), the Render event starts again with empty rows (earlier check/radio controls are not there).  New controls are .Created for each row each time.
> > 
> > My question is this:  When do the controls I place in cells get destroyed?  Are they accumulating somewhere, or is the IWGrid destroying them when it refreshes the grid?  
> 
> Well... I'm not sure about the code you are using, but consider this piece of code:
 
Code (below) was  in an earlier message in this thread.

{code}
if ARow > 0 then
  begin
   if AColumn = 0 then
    begin
     if Assigned(ACell.Control) = False then
      begin
           ACell.Control := TIWRadioButton.Create(Self);
           with TIWRadioButton(ACell.Control) do
            begin
              Name:=self.Name+'RowSelector'+inttostr(ARow);
             OnAsyncChange:=optTempRadioButtonAsyncChange;
             Tag:=ARow;
             SubmitOnAsyncEvent:=true;
             Caption:='';
             Checked := false;
            end;
      end;
    end;
{code}

I'm not using FillCells, since this is a DBGrid and cells fill from the datasource.  So, I created them as above, in the OnRenderCell.

Interestingly, when I check Self.ControlCount I only get a count equivalent to the count originally on the form, whether I check the count before rendering the grid, while the grid is showing, or after it is changed.  The controls I added to cells simply are not in the count.  Is the {cell}.Control being used as a real control, or maybe only lives long enough to render the cell then dropped??

If not, where does the control go?  I am using TIWRadioButton.Create(Self) as shown above so the control(s) should be owned by the IWForm, right?

Also, I could not find documentation on refreshing the DBgrid after a dataset change.  I ran across DoRefreshControl and that seemed to work.  Is that the proper method?  e.g.:

{code}
  dsMyData.Active:=false;
  dsMyData.CommandText:=NewQuery;
  dsMyData.Active:=true;
  ThisDBGrid.DoRefreshControl:=true;
{code}

Thanks,
Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 23-Jan-2015, at 5:07 PM EST
From: Dan Barclay
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Alexandre Machado wrote:}{quote}
> 
> you are changing the PARENT of the IWLink control (the parent becomes the IWGrid itself), but you don't change the owner. In our case, the owner is the IWForm (the IWLink instance is created as TIWLink.Create(self) ), so the IWForm will release all IWLink instances when it is destroyed.
> If your IWControls are owned by the IWForm, then they will be destroyed anyway, but there may be a problem there: If you create new controls each time that the IWForm renders, then you may get hundreds or thousands of IWControl instances before the IWForm is destroyed. In this case, you should destroy all the "old" controls, before creating new ones.

Thanks.  That is what I had expected, but had hoped there was some code that would take care of destroying the cell controls when the grid was recreated.  Bottom line:  The cell controls become orphaned (parent lost), though owned by the form, no?

This is for the IWDBGrid, so I'm not filling the grid myself.  A Control is added during the RenderCell event.  When the DataSet changes the grid, cells that present themselves for rendering no longer have the control that was created previously so I can't re-use them directly.

My understanding is that [form].Release as the IW equivalent of Free and would destroy it and the things it owns.  If so, in my current case, I'm not going to worry about a basket of orphaned controls because it would be short term and not enough to hurt anything.  

That said, if I wanted to clean up the orphaned controls where would I do that (for the DB grid)?  Event order is not clear to me.  I wouldn't want to kill them once I started adding controls for "new" cells.   It appears that the grid.OnRender event fires prior to the OnRenderCell events.  Is that always the order, and could I cleanup the previously used controls there?  Is there a difference in how to find controls on IWForms vs VCL forms?

Thanks,
Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 23-Jan-2015, at 3:50 PM EST
From: Dan Barclay
 
Re: IWDBGrid row select, click, doubleclick. [Edit]  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Dan Barclay wrote:}{quote}
> > {quote:title=Alexandre Machado wrote:}{quote}
> > > {quote:title=Dan Barclay wrote:}{quote}
> > > Bug in IWDBGrid or IWRadioButton?  Or did I miss something?
> > 
> > I'll try to reproduce and let you know, OK?
> Maybe you can answer another question while you're looking at that.
> 
> When I add the check/radio control to the row I create it as shown in the code above.
> 
> I have found that anytime the grid is refreshed (change query for example), the Render event starts again with empty rows (earlier check/radio controls are not there).  New controls are .Created for each row each time.
> 
> My question is this:  When do the controls I place in cells get destroyed?  Are they accumulating somewhere, or is the IWGrid destroying them when it refreshes the grid?  

Well... I'm not sure about the code you are using, but consider this piece of code:

{code}

procedure TIWForm1.FillGrid(const aRowCount: Integer);
var
  i: Integer;
  IWLink: TIWLink;
begin
  // setup grid
  IWGrid1.Clear;
  IWGrid1.RowCount := aRowCount;
  IWGrid1.ColumnCount := 1;
  // fill cells
  for i := 0 to aRowCount - 1 do
  begin
    // create the IWLink instance and set its properties
    IWLink := TIWLink.Create(self);
    IWLink.Text := 'demo ' + IntToStr(i);
    IWLink.Tag := aRowCount;
    IWLink.OnAsyncClick := DoGridCellClickAsync;
    // set the cell control
    IWGrid1.Cell[i, 0].Control := IWLink;
  end;
end;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
begin
  // Add 5 lines to the IWGrid, each line contains a TIWLink as the cell control
  FillGrid(5);
end;

{code}

In the above example, the grid controls are created just once, when the form is created. Everytime the grid is rendered again, the controls are still there (you can press F5 or do a POST request) and everything works as expected.

When you set the cell control:

IWGrid1.Cell[i, 0].Control := IWLink;

you are changing the PARENT of the IWLink control (the parent becomes the IWGrid itself), but you don't change the owner. In our case, the owner is the IWForm (the IWLink instance is created as TIWLink.Create(self) ), so the IWForm will release all IWLink instances when it is destroyed.
If your IWControls are owned by the IWForm, then they will be destroyed anyway, but there may be a problem there: If you create new controls each time that the IWForm renders, then you may get hundreds or thousands of IWControl instances before the IWForm is destroyed. In this case, you should destroy all the "old" controls, before creating new ones.

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 23-Jan-2015, at 2:45 AM EST
From: Alexandre Machado
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Alexandre Machado wrote:}{quote}
> > {quote:title=Dan Barclay wrote:}{quote}
> > Bug in IWDBGrid or IWRadioButton?  Or did I miss something?
> 
> I'll try to reproduce and let you know, OK?
Maybe you can answer another question while you're looking at that.

When I add the check/radio control to the row I create it as shown in the code above.

I have found that anytime the grid is refreshed (change query for example), the Render event starts again with empty rows (earlier check/radio controls are not there).  New controls are .Created for each row each time.

My question is this:  When do the controls I place in cells get destroyed?  Are they accumulating somewhere, or is the IWGrid destroying them when it refreshes the grid?  

Do I need to release the form to free these components (I'd planned to let the form live until I need it again)?

Thanks,
Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Jan-2015, at 2:50 PM EST
From: Dan Barclay
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Registered User wrote:}{quote}
> Hi Dan,
> 
> The Grid and DBGrid components of AToZed don't have much functionality.
> The Grid and DBGrid components of TMS or CGDevTools do have much more 
> functionalities.
> 
> I don't know if you have the possibility of bying 3rd party tools, but you 
> could consider it.
> 
> Regards, Paul

Third party controls are a possibility, and I may use those.  I first try to stay as "native" as possible.  For this use, the straight control will probably be sufficient.  When I use 3rd party controls it is because I need some really extended functionality, typically.

That said, I use 3rd party library when needed and when I can get source.  It's been a couple of decades now, but I relied on a library whose vendor got bought then went under (without opening source).   That was painful, so while I do absolutely love some 3rd party solutions I am (sometimes overly) cautious.

In fact, we are currently unable to compile IW Ultimate base code in XE2 (which I reported elsewhere here) and that bothers me as well.  I have tried the last two builds, but haven't downloaded the latest released this week.

Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Jan-2015, at 2:35 PM EST
From: Dan Barclay
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Alexandre Machado wrote:}{quote}
> > {quote:title=Dan Barclay wrote:}{quote}
> > Bug in IWDBGrid or IWRadioButton?  Or did I miss something?
> 
> I'll try to reproduce and let you know, OK?

Great.  Thanks.

While you are looking, be aware that it only emits an event when it changes to On.  The button changing from On to Off does not report.  

That means that I can, for now, know that the control.Checked property is "true",  even though it says "false".  I can therefore make my dialog work OK.

HOWEVER, if you fix the control so that both changed buttons emit events then I will no longer know which has turned True and which has turned False.  I'm thinking the button turning False should also emit an event, but if you fix that then please fix the control.Checked problem first .

Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Jan-2015, at 2:28 PM EST
From: Dan Barclay
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
> {quote:title=Dan Barclay wrote:}{quote}
> Bug in IWDBGrid or IWRadioButton?  Or did I miss something?

I'll try to reproduce and let you know, OK?

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Jan-2015, at 2:19 PM EST
From: Alexandre Machado
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
Hi Dan,

The Grid and DBGrid components of AToZed don't have much functionality.
The Grid and DBGrid components of TMS or CGDevTools do have much more 
functionalities.

I don't know if you have the possibility of bying 3rd party tools, but you 
could consider it.

Regards, Paul


"Dan Barclay" schreef in bericht news:710804@forums.embarcadero.com...

Bug in IWDBGrid or IWRadioButton?  Or did I miss something?

Reproduce:
XE2,
IntraWeb Ultimate Edition
IntraWeb Version: 14.0.36


Create a grid with data.
In the  ...RenderCell() event

{code}
if ARow > 0 then
  begin
   if AColumn = 0 then
    begin
     if Assigned(ACell.Control) = False then
      begin
           ACell.Control := TIWRadioButton.Create(Self);
           with TIWRadioButton(ACell.Control) do
            begin
              Name:=self.Name+'RowSelector'+inttostr(ARow);
             OnAsyncChange:=optTempRadioButtonAsyncChange;
             Tag:=ARow;
             SubmitOnAsyncEvent:=true;
             Caption:='';
             Checked := false;
            end;
      end;
    end;
{code}

In the optTempRadioButtonAsyncChange event used above
{code}
Info:='Action: Tag/Value ' +inttostr(TIWRadioButton(Sender).tag)+' / 
'+BSBoolToString(TIWRadioButton(Sender).Checked)
{code}

Display grid.  Select various rows.

The "Checked" property is always False.  Reviewing the EventParams.Text 
indicates that the value of that button is being properly returned ( ex: 
Includes "FRMTRANPICKIROWSELECTOR2_INPUT=on") for the Checked control.

Note that when I use a TIWCheckBox instead of TIWRadioButton in this same 
code I get the value of the button.

A RadioButton on the form itself (not on the grid) will properly show the 
..Checked value in the asyncChange event.

Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 22-Jan-2015, at 4:23 AM EST
From: Registered User
 
Re: IWDBGrid row select, click, doubleclick.  
News Group: embarcadero.public.delphi.thirdpartytools.intraweb
Bug in IWDBGrid or IWRadioButton?  Or did I miss something?

Reproduce:
XE2, 
IntraWeb Ultimate Edition
IntraWeb Version: 14.0.36


Create a grid with data.
In the  ...RenderCell() event

{code}
 if ARow > 0 then
  begin
   if AColumn = 0 then
    begin
     if Assigned(ACell.Control) = False then
      begin
           ACell.Control := TIWRadioButton.Create(Self);
           with TIWRadioButton(ACell.Control) do
            begin
              Name:=self.Name+'RowSelector'+inttostr(ARow);
             OnAsyncChange:=optTempRadioButtonAsyncChange;
             Tag:=ARow;
             SubmitOnAsyncEvent:=true;
             Caption:='';
             Checked := false;
            end;
      end;
    end;
{code}

In the optTempRadioButtonAsyncChange event used above
{code}
Info:='Action: Tag/Value ' +inttostr(TIWRadioButton(Sender).tag)+' / '+BSBoolToString(TIWRadioButton(Sender).Checked)
{code}

Display grid.  Select various rows.

The "Checked" property is always False.  Reviewing the EventParams.Text indicates that the value of that button is being properly returned ( ex:  Includes "FRMTRANPICKIROWSELECTOR2_INPUT=on") for the Checked control.

Note that when I use a TIWCheckBox instead of TIWRadioButton in this same code I get the value of the button.

A RadioButton on the form itself (not on the grid) will properly show the .Checked value in the asyncChange event.

Dan

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 21-Jan-2015, at 6:32 PM EST
From: Dan Barclay