Jump to content

How to change ImageIndex on the TUniActionColumn depends on DataSet Data?


Tokay

Recommended Posts

A DbGrid has action column with one button. It's necesserry to change image on the buttons depends of current dataset row data. The difficulty is that UniDBGrid1DrawColumnCell does not fired on such columns, if I understand correctly. Maybe this is a bug or it works by disign in such way?

I'm use 1551 version.

Link to comment
Share on other sites

2 hours ago, Tokay said:

A DbGrid has action column with one button. It's necesserry to change image on the buttons depends of current dataset row data. The difficulty is that UniDBGrid1DrawColumnCell does not fired on such columns, if I understand correctly. Maybe this is a bug or it works by disign in such way?

Hello,

This post may help you:

 

Link to comment
Share on other sites

Unfortunatelly I have no find any example how to change image depended on dataset.

I additionally explain what is nedded to achive:

row 1 has 0 value in the 2 column (with action buttons), then we show on grid button Image 0 from bineded TUniNativeImageList;

row 2 has 4 value in the 2 column (with action buttons), then we show on grid button Image 4 from bineded TUniNativeImageList;

row 3 has 2 value in the 2 column (with action buttons), then we show on grid button Image 2 from bineded TUniNativeImageList;

and in that way all other rows.

Link to comment
Share on other sites

57 minutes ago, Tokay said:

Unfortunatelly I have no find any example how to change image depended on dataset.

I did not say that there is a solution that meets your needs.

Here you will find an alternative solution that may help you:

ActionIconCls.png.1f570d676aeb6e1ed8cdc450d8f19a48.png

Link to comment
Share on other sites

13 minutes ago, Tokay said:

Actually the data is in the 'Actions' column, not in the other. I.e. really need to show data (four states of the row/record) in the 'Actions' as buttons with different icons with action on they.

In that case, maybe you should use widget column?

Link to comment
Share on other sites

36 minutes ago, Tokay said:

Na verdade, os dados estão na coluna 'Ações', não na outra. Ou seja, realmente precisa mostrar os dados (quatro estados da linha/registro) nas 'Ações' como botões com ícones diferentes com ação neles.

Sorry for getting in here, in that case I couldn't use TField's GetText?

Link to comment
Share on other sites

9 hours ago, Tokay said:

Actually the data is in the 'Actions' column, not in the other. I.e. really need to show data (four states of the row/record) in the 'Actions' as buttons with different icons with action on they.

 

8 hours ago, Sherzod said:

In that case, maybe you should use widget column?

Using UniButtonWidget:

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniDBGrid1.ClientEvents.ExtEvents.Values['reconfigure'] :=
    'function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)'+
    '{                                                                        '+
    '    var widgetColIndx=1;                                                 '+
    '    columns[widgetColIndx].onWidgetAttach = function(column, widget, record) {'+
    '        if (record.get(widgetColIndx) == "Blue Angelfish") {                  '+
    '            widget.setIcon("'+ UniMainModule.UniNativeImageList1.GetImagePngUrl(0) +'")'+
    '        } else {                                                              '+
    '            widget.setIcon("'+ UniMainModule.UniNativeImageList1.GetImagePngUrl(1) +'")'+
    '        }                                                                     '+
    '    };                                                                        '+
    '}                                                                             '
end;

image.thumb.png.a2fe6f4a526187130000dd1283bac98d.png

Link to comment
Share on other sites

2 minutes ago, Tokay said:

yes for both questions

procedure TMainForm.UniFormCreate(Sender: TObject);
begin
  UniDBGrid1.ClientEvents.ExtEvents.Values['reconfigure'] :=
    'function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)'+
    '{                                                                        '+
    '    var widgetColIndx='+ UniDBGrid1.Columns[1].Index.ToString() +';'+
    '    columns[widgetColIndx].onWidgetAttach = function(column, widget, record) {'+
   '        if (record.get(widgetColIndx) == "Blue Angelfish") {                  '+
    '            widget.setIcon("'+ UniMainModule.UniNativeImageList1.GetImagePngUrl(0) +'")'+
    '        } else {                                                              '+
    '            widget.setIcon("'+ UniMainModule.UniNativeImageList1.GetImagePngUrl(1) +'")'+
    '        }                                                                     '+
    '    };                                                                        '+
    '}                                                                             '
end;

?

Link to comment
Share on other sites

41 minutes ago, Tokay said:

Another moment. How to find moved column? User can change column number during work.

Hi, I'm just drawing the NativeImagelist image from ActionButton Graphics when I create the query.

Depending on a specific field in the table, I can put the necessary pictures.
I do this on the server side.

Link to comment
Share on other sites

6 minutes ago, Tokay said:

Hi, is much better to share code 😀 Thank you!

1. 

var

myBMP : TMemmoryStream;

TempBmp: TBitmap;

TRY
  wei := TuniImage (MyClass).width;
  hei := TuniImage (MyClass).Height;
  myBMP := TMemoryStream.Create;
  TempBmp.SaveToStream(myBMP);
  myBMP.Position := 0;
  if (myBMP.Size > 0)
  AND (myBMP.Size <= TRUNC (20*1024*1024))
  then begin
        TuniImage (MyClass).Picture.Bitmap.Canvas.Lock;
        TuniImage (MyClass).Picture.Bitmap.LoadFromStream(myBMP);
        TuniImage (MyClass).Picture.Bitmap.Canvas.UnLock;
   end;
EXCEPT
    on E:Exception do begin
END;
 myBMP.Size := 0;
 TempBmp.Free;
 myBMP.Free;
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...