Jump to content

Recommended Posts

Posted

Hello!

 

I'm using UniDBGrid with a dataset has looukup field. I need a solution to clear that field, but I don't want to assign UniDBLookupComboBox to that columns. I can clear the lookup field at OnKeyDown event but then I can't close the combo when it is shown. The value of the field cleared but the lookup combo still shows the last value of that field.  Is there a way to close that programatically ? Thanks in advance.

 

Art

Posted

Hello,

just to better understand your case:

1. Would you be able to share a screenshot of the situation you're describing (before and after clearing the field)?

2. Also, how exactly are you clearing the lookup field programmatically? Are you using Field.Clear, Field.Value := null, or something else?

If you could provide a minimal test case or simple steps to reproduce, that would help a lot in finding the best solution — especially if you're not using UniDBLookupComboBox directly in the column.

Posted

Hello!

Thx for your help. The Ksh column contains the lookup field.

This is before the situation before clear

image.png.f9106326fc673bf034544b148062b876.png

And when I click on it.

image.png.e9d6c910ebe8e351994be514d5e65682.png

 

this is where i handle the keydown event:
procedure TUniFrameDBGrid.UniDBGridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_DELETE) and (ssCtrl in Shift) then
    if ( UniDBGrid.Columns[UniDBGrid.CurrCol].Field <> nil) and ( UniDBGrid.Columns[UniDBGrid.CurrCol].Field.Lookup ) then
      begin
        if not ( UniDBGrid.DataSource.DataSet.State in [dsEdit,dsInsert] ) then
          UniDBGrid.DataSource.DataSet.Edit;
        UniDBGrid.DataSource.DataSet.FieldByName(UniDBGrid.Columns[UniDBGrid.CurrCol].Field.KeyFields).Value := Null;
        UniDBGrid.DataSource.DataSet.Post;
        Key := 0;
      end;
end;

It looks like after keypress:
image.png.7b9776e843bd632bc158eaeb0cd06c87.png

At this moment the value of the field is null. When I press and escape the result is:

image.png.5da582890b10400091212a86e768ccc3.png

My goal would be as seen at the last image. When I press ctrl + delete than close the editor combo.
Thanx in advance.

Art
 

 

Posted

Hallo!

 

Can someone put me in the right direction ? What is the simlest solution to clear lookup field value without assigning a DBLookupComboBox to it ?
Thx in advance.

 

Art

Posted
31 minutes ago, art said:

Can someone put me in the right direction ? What is the simlest solution to clear lookup field value without assigning a DBLookupComboBox to it ?

Hello,

I forgot about your request, which I didn't quite understand, sorry.
Can you create a simple test case to reproduce?

Posted

Hello!

If you open the example in the Demos\Desktop\GridLookupField folder and set the keydown event to this:
procedure TMainForm.UniDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_DELETE) and (ssCtrl in Shift) then
    if ( UniDBGrid1.Columns[UniDBGrid1.CurrCol].Field <> nil) and ( UniDBGrid1.Columns[UniDBGrid1.CurrCol].Field.Lookup ) then
      begin
        if not ( UniDBGrid1.DataSource.DataSet.State in [dsEdit,dsInsert] ) then
          UniDBGrid1.DataSource.DataSet.Edit;
        UniDBGrid1.DataSource.DataSet.FieldByName(UniDBGrid1.Columns[UniDBGrid1.CurrCol].Field.KeyFields).Value := Null;
        UniDBGrid1.DataSource.DataSet.Post;
        Key := 0;
      end;
end;

If you click a capital cell that conains some value for example Ottawa and Canada and the combobox is visible ( closed up or dropped down ) and you press Ctrl + Delete the value of the cell will be null but the combobox will not be empty. It shows only one item that is equal the old value of the cell. At this situation you can see that capital and country cleared but the combo show Buenos Aires.

image.png.3747211c95efb8ade457567578f4d223.png

 

The expected behavior would be an empty or closed combobox.

Thanx in advance.

 

 

 

 

 

Posted

Hello!

 

It's pitiful but it is working:

 

procedure TUniFrameDBGrid.UniDBGridKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_DELETE) and (ssCtrl in Shift) then
    if ( UniDBGrid.Columns[UniDBGrid.CurrCol].Field <> nil) and ( UniDBGrid.Columns[UniDBGrid.CurrCol].Field.Lookup ) then
      begin
        if not ( UniDBGrid.DataSource.DataSet.State in [dsEdit,dsInsert] ) then
          UniDBGrid.DataSource.DataSet.Edit;
        UniDBGrid.DataSource.DataSet.FieldByName(UniDBGrid.Columns[UniDBGrid.CurrCol].Field.KeyFields).Value := Null;
        UniDBGrid.DataSource.DataSet.Post;
        if ( UniDBGrid.CurrCol > 0 ) then
          begin
            UniDBGrid.CurrCol := UniDBGrid.CurrCol - 1;
            UniDBGrid.CurrCol := UniDBGrid.CurrCol + 1;
          end
        else if ( UniDBGrid.CurrCol < UniDBGrid.Columns.Count - 1 ) then
          begin
            UniDBGrid.CurrCol := UniDBGrid.CurrCol + 1;
            UniDBGrid.CurrCol := UniDBGrid.CurrCol - 1;
          end;
        Key := 0;
      end;
end;

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