art Posted April 3 Posted April 3 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 Quote
Sherzod Posted April 3 Posted April 3 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. Quote
art Posted April 3 Author Posted April 3 Hello! Thx for your help. The Ksh column contains the lookup field. This is before the situation before clear And when I click on it. 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: At this moment the value of the field is null. When I press and escape the result is: My goal would be as seen at the last image. When I press ctrl + delete than close the editor combo. Thanx in advance. Art Quote
art Posted April 8 Author Posted April 8 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 Quote
Sherzod Posted April 8 Posted April 8 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? Quote
art Posted April 14 Author Posted April 14 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. The expected behavior would be an empty or closed combobox. Thanx in advance. Quote
art Posted April 19 Author Posted April 19 Hello ! Is there any way to close combobox programatically in dbgrid ? Thx in advance Quote
art Posted April 21 Author Posted April 21 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; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.