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...
5 hours ago, kentiger said:

Ver: 1.90.0.1547 Trial

I follow the Sherzod method

Error Message:  TuniCustomDBgrid.SetCellValue: RecNo Mismatch![4: -1].

Please help, thank you

 

 

Hello

Can you please create a test case?

Link to comment
Share on other sites

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

1 hour ago, Hayri ASLAN said:

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.

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

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...