Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Intraweb 15.1.5 - IWEdit in IWGrid.Cell problem
#1
Hi

I have a TIWGrid Control with 6 columns and 10 rows.

For all cells in grid I create a TIWEdit Control. (button Fill)

procedure TIWMainForm.IWButton1Click(Sender: TObject);
var
  i, j: Integer;
begin
  for j := 0 to IWGrid1.RowCount - 1 do
    for i := 0 to IWGrid1.ColumnCount - 1 do
    begin
      with IWGrid1.Cell[j, i] do
      begin
        Alignment := taCenter;
        Width    := IntToStr(Round(IWGrid1.Width / IWGrid1.ColumnCount));

        Control := TMyIWEdit.Create(IWGrid1);
        with TMyIWEdit(Control) do
        begin
          X := i;
          Y := j;
          Text := '';
          Width := StrToInt(IWGrid1.Cell[j, i].Width) - 10;
          OnAsyncKeyDown := OnAsyncKeyDownControl;
          OnAsyncClick  := OnAsyncClickControl;
        end;
      end;
    end;
  SetFocus(0, 0);
end;

   

Any IWEdit control has attached procedure for OnAsyncKeyDown event (code below).

The procedure realize the below behavior:

When enter to first control in any rows, enter any value to IWEdit control in selected cell and push enter key
all other IWEdit controls in current row will have the same value.

And here is a problem.

All IWEdit controls in current row, wchich have changed value, are move to left, upper corner of IWGrid control.

   

In Intraweb ver. 14.2.6  i haven't the problem..
In Intraweb ver. 15.1.6 problem exists.

Where can be a problem?

Test project:

https://github.com/PeterDelphinsky/IWGridTest

procedure TIWMainForm.OnAsyncKeyDownControl(Sender: TObject;
  EventParams: TStringList);
var
  pKey: Integer;
  pText: String;
  i: Integer;
begin

  if not TryStrToInt(EventParams.Values['Which'],pKey) then
    pKey := 0;

  if pKey = 13 then
  begin

    pText := IWGrid1.Cell[Y, X].Control.Text;

    if (X = 0) and (pText <> '') then
    begin

      for i := X + 1 to IWGrid1.ColumnCount - 1 do
        IWGrid1.Cell[Y, i].Control.Text := pText;  //<-- 

      Exit;
    end;
    
//   (...)

  end;
end;
Reply
#2
The buttons will need a unique 'Name' value assigned after being created.  Something like:

        Control := TMyIWEdit.Create(IWGrid1);
        with TMyIWEdit(Control) do
        begin
          Name := 'btn'+IntToStr(i)+IntToStr(j);
...
Reply
#3
(10-05-2019, 05:34 PM)MJS@mjs.us Wrote: The buttons will need a unique 'Name' value assigned after being created.  Something like:

        Control := TMyIWEdit.Create(IWGrid1);
        with TMyIWEdit(Control) do
        begin
          Name := 'btn'+IntToStr(i)+IntToStr(j);
...

thanks, but problem still exists... :-(

Piotr Lewicki
Reply
#4
The button 'Parent' value may need to be set also.
Reply
#5
(10-05-2019, 06:50 PM)MJS@mjs.us Wrote: The button 'Parent' value may need to be set also.

Parent is TWinControl, but IWComponents don't inherit from TWinControls....?

TIWEdit(Control).Parent := IWGrid -> [dcc32 Error] IWMainFrm.pas(70): E2010 Incompatible types: 'TWinControl' and 'TIWGrid'

PLE
Reply
#6
Interesting... what about setting the TIWEdit 'Parent' to the form?
Reply
#7
(10-05-2019, 09:02 PM)MJS@mjs.us Wrote: Interesting... what about setting the TIWEdit 'Parent' to the form?

TIWMainForm
  -->TIWRegion
    -->TIWGrid
       -->Cell[row,col]
          -->Control = TIWEdit

How do you think, what is Parent for Control in Cell?

If I set Parent as TIWMainForm, my IWGrid renders incorrectly. 

PLE
Reply
#8
(10-05-2019, 06:10 PM)piotr.lewicki@mapi.com.pl Wrote:
(10-05-2019, 05:34 PM)MJS@mjs.us Wrote: The buttons will need a unique 'Name' value assigned after being created.  Something like:

        Control := TMyIWEdit.Create(IWGrid1);
        with TMyIWEdit(Control) do
        begin
          Name := 'btn'+IntToStr(i)+IntToStr(j);
...

thanks, but problem still exists... :-(
 Be sure to assign the unique name.  Unique to the page, so be sure there isn't another 'btnXY'.  I use the grid .name in front like
     Name:=self.name+'btn'[b]+IntToStr(i)+IntToStr(j);[/b]
It's too easy to duplicate a name with something else on the page and HTML simply won't put up with it.

I don't use edit controls, but with checkboxes and radio boxes I also include.
   SubmitOnAsyncEvent:=true;

I manage all of my cell controls in the grid RenderCell procedure.  That involves checking to insure that cell's control is not already created.

Another point, although it's supposed to be OK, I just don't cascade "with" statements.   Having the IWEdit inside the Cell should be fine, I just don't trust it.  (others will disagree with me on that!)

Dan
Reply
#9
You can check in our Demos to see. Off hand I dont think a parent is set for grid based controls but the demo will show for sure the right way.
Reply
#10
Thanks for all, but problem still exists.

Why the same code is working in old version (14) of Intraweb , but in new  version (15) doesn't.

Still I'm looking a solution...

Have a nice day.
PLE
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)