Jump to content

How to Append A new row in Grid when VK_DOWN key pressed


molla2005b

Recommended Posts

Hi,

 

You can try like this:

 

1.

type
  TUniExDBGrid = class(TUniDBGrid)
end;

2.

procedure TMainForm.UniDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  isLastRecord: Boolean;
begin
  isLastRecord := (Sender as TUniDBGrid).DataSource.DataSet.RecNo = (Sender as TUniDBGrid).DataSource.DataSet.RecordCount;
  
  if (Key = VK_TAB)and(isLastRecord)and(TUniExDBGrid(Sender).CurrCol=(Sender as TUniDBGrid).Columns.Count-1) then
  begin
    // your logic
    (Sender as TUniDBGrid).DataSource.DataSet.Append;
  end;
end;

Best regards.

Link to comment
Share on other sites

  • 4 years later...
6 minutes ago, eduardosuruagy said:

This error is old and they have never been able to correct it.

Hello

This error happens when you make changes when grid is dirty. There is no way to fix this error as you need to change your code. This error is a precaution.

Link to comment
Share on other sites

14 minutes ago, eduardosuruagy said:

Sorry, I didn't understand the translation of what would be "grid is dirty"

Hello

If grid needs to refresh itself, that means grid is dirty.

Let say you have 3 records and in server side you refreshed the query and you have 4 records now.

In the client side grid needs to refresh. Before it refresh if you try to access 4th record in client side, you will get error.

Link to comment
Share on other sites

2 hours ago, Hayri ASLAN said:

Olá

Se a grade precisa se atualizar, isso significa que a grade está suja.

Digamos que você tenha 3 registros e no lado do servidor você atualizou a consulta e agora tem 4 registros.

Na grade do lado do cliente precisa ser atualizada. Antes de atualizar, se você tentar acessar o 4º registro no lado do cliente, obterá um erro.

can you show me an example?

 

I do a lot this way, I don't know if it's correct.

DataSet.Edit;
DataSet.FieldByName ('FIELD'). AsString: = 'Value';
DataSet.Post;
DataSet.ApplyUpdate (0);
DataSet.RefreshRecord;
dbgrid.RefreshCurrentRow ();

Link to comment
Share on other sites

Hi, Hayri ASLAN

UniDbgrid1 have 3 Column

      badno    badname    description

My needs:

When in the add mode, after the user enters the data in the Description, press the down button, the system automatically Append new record

The following is my program

procedure TMainForm.UniDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  isLastRecord: Boolean;
begin
  isLastRecord := Abs((Sender as TUniDBGrid).DataSource.DataSet.RecNo) = (Sender as TUniDBGrid).DataSource.DataSet.RecordCount;
  if (Key = VK_DOWN) and (isLastRecord) and(TUniDBGrid(Sender).CurrCol=(Sender as TUniDBGrid).Columns.Count-1) then
  begin
    (Sender as TUniDBGrid).DataSource.DataSet.Append;
  end;
end;

 

An error message will occur as follows-->TuniCustomDBgrid.SetCellValue: RecNo Mismatch![4: -1].

 

Please help, thank you

 

 

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