Jump to content

TUniDbgrid how get cell value and column name from cell?


Ulugbek

Recommended Posts

10x

Mohammad

How with button click get not cell click ..

 

I try this but this work only first column

procedure TMainForm.est1Click(Sender: TObject);
var
 val1:string;
 clmn_name1:string;
begin
  val1:=UniDBGrid1.Columns[0].Field.AsString;
  clmn_name1:=UniDBGrid1.Columns[0].Field.FieldName;
  ShowMessage(Concat(val1,'  ',clmn_name1));
end;
Link to comment
Share on other sites

Hi Ulugbek.

 

 

Try this:

type
  TDBGridHack = class(TuniDBGrid)
    private
      function GetCurrCol: Integer;    
  end;
function TDBGridHack.GetCurrCol: Integer;
begin
  Result := CurrCol;
end;
procedure TMainForm.UniBitBtn1Click(Sender: TObject);
var i: Integer;
begin
  i := TDBGridHack(UniDBGrid1).GetCurrCol;
  ShowMessage(UniDBGrid1.Columns[i].Field.AsString + '   ' + UniDBGrid1.Columns[i].FieldName);
end;
Link to comment
Share on other sites

  • 4 years later...

Hello there ! (:

 

is it possible to access the value of a the current cell in onKeyDown event ?

Here's the use case: 

  • I'm in my cell, updating my value
  • I press for instance F3 key for a specific action
  • I obtain the cell value (the dataSource have not been update yet so UniDBGrid1.Columns[i].Field.AsString give the old value!)
  • Do my stuff.

How my I obtain the cell value ?

 

Regards,

Link to comment
Share on other sites

  • 3 weeks later...

Hi,

 

Hello there ! (:

 

is it possible to access the value of a the current cell in onKeyDown event ?

Here's the use case: 

 

  • I'm in my cell, updating my value
  • I press for instance F3 key for a specific action
  • I obtain the cell value (the dataSource have not been update yet so UniDBGrid1.Columns[i].Field.AsString give the old value!)
  • Do my stuff.
How my I obtain the cell value ?

 

Regards,

Sorry, can you make a simple testcase for this?..

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Perhaps this solution is not very suitable for you, but try this "workaround":

1. UniDBGrid -> OnKeyDown, do not use this event:

procedure TMainForm.UniDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
//  do not use this event
//  if Key = vk_F4 then
//  begin
//    ShowMessage('Cell value is '''+UniDBGrid1.Columns[UniDBGrid1.CurrCol].Field.AsString+'''.');
//  end;
end;

2. UniDBGrid -> ClientEvents -> ExtEvents -> function reconfigure:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) 
{
    columns.forEach(function(col) {
        if (col.getEditor()) {
            col.getEditor().on('keydown', function(field, e) {
                if (e.keyCode == 115) {
                    // keyCode can also be passed
                    ajaxRequest(sender, '_keydown', ['val=' + field.value])
                }
            })
        }
    })
}

3. UniDBGrid -> OnAjaxEvent:

procedure TMainForm.UniDBGrid1AjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
begin
  if EventName = '_keydown' then
    ShowMessage(Params.Values['val']);

end;

 

Link to comment
Share on other sites

Hey Sherzod,

thanks for the answer !! :D

There is a problem with editor's event :

col.getEditor().on('keydown', function(field, e) {

as it is never fired! Did I miss something ??:O

But I managed to extract field value with this code, if anyone need it ! ^_^

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts)
{
   columns.forEach(function(col){
     if(col.getEditor()){
       console.log(col.getEditor());
       sender.on('keydown', function(e, t, eOpts){
       console.log(e.keyCode);
              
         if(e.keyCode == 115){
           ajaxRequest(sender, '_keydown', ['val='+col.field.value]);
         }
       })     
     }
   })
}

 

On 10/31/2018 at 8:27 PM, Sherzod said:

Perhaps this solution is not very suitable for you

I am going to validate this with my manager and give you a feedback on that solution ! (:

Link to comment
Share on other sites

  • 4 years later...

Testcase made from demo project. You can just focus DBGrid and click any key. Alert should be shown but it is not. 

 

2. UniDBGrid -> ClientEvents -> ExtEvents -> function reconfigure:

function reconfigure(sender, store, columns, oldStore, oldColumns, eOpts) 
{
    columns.forEach(function(col) {
        if (col.getEditor()) {
            col.getEditor().on('keydown', function(field, e) {
                if (e.keyCode == 115) {
                    // keyCode can also be passed
                    ajaxRequest(sender, '_keydown', ['val=' + field.value])
                }
            })
        }
    })
}

The part :

col.getEditor().on('keydown', function(field, e) { ...}

This function does not fire. 

 

 

 

 

Grid - Infinite Scroll.zip

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...