Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 19 Apr 2024, 09:36

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 20 Mar 2012, 11:24 
Offline

Joined: 09 Feb 2012, 17:05
Posts: 124
Hello,

Could you say me how to have a lookup field not nullable in a DBGridEh ?

I want that my users choose values in lookup combo, but I don't want they by able to clear the field by pressing Del or BackSpace keys (I have a null value in my DataBase after).

Why the TColumnEh..OnNotInList event is not execute on null value ?

I can use the event KeyDown on the dbGrid, but it's not usefull ...

@Dmitry : Have you plan something to have this feature ? (a property on colums like 'Nullable' or 'DeleteKeyClear')

Thank You

Rico


Last edited by Rico on 20 Mar 2012, 14:00, edited 1 time in total.

Top
 Profile  
 
PostPosted: 20 Mar 2012, 13:33 
Offline

Joined: 19 Jan 2012, 20:54
Posts: 12
May be use event OnChange or OnChangeKeyValue and check for example:
Code:
if dbLookupcomboBoxEh1.KeyValue = Null then
  dbLookupcomboBoxEh1.KeyValue := 1; // you value by default


Top
 Profile  
 
PostPosted: 20 Mar 2012, 13:58 
Offline

Joined: 09 Feb 2012, 17:05
Posts: 124
sinys wrote:
May be use event OnChange or OnChangeKeyValue and check for example:
Code:
if dbLookupcomboBoxEh1.KeyValue = Null then
  dbLookupcomboBoxEh1.KeyValue := 1; // you value by default


Hello sinys,

I don't need to do that in a dbLookupcomboBoxEh but in a lookupCombo in the DBGridEh ;)
There isn't such event in the column and the only one is TColumnEh.OnNotInList, but it doesn't work for null values

With TColumnEh.UpdateData I could set a value, but I don't have the old value in this event ...


Rico


Top
 Profile  
 
PostPosted: 20 Mar 2012, 15:24 
Offline
Администратор

Joined: 22 Dec 2011, 20:19
Posts: 335
Hello Rico.

What about property - TField.Required. Can you use this property?

_________________
Best regards
Admin


Top
 Profile  
 
PostPosted: 20 Mar 2012, 16:57 
Offline

Joined: 09 Feb 2012, 17:05
Posts: 124
Administrator wrote:
Hello Rico.

What about property - TField.Required. Can you use this property?


Hello Dmitry,

I try it and I have the message "Field [MYFIEILD] required ...." when the data is posted
While the data is not posted, there is no message, so you can input values in others fields before have the message

This message don't speak to end users and they must press Escape to abort changes, but Escape abort all changes done on the record !!, so all changes are lost ...

Not very usefull this method as you can see ... (I think the message appears too late to be used in a grid)

You don't think that add a property to columns will be the best solution ?
(or modify TColumnEh.OnNotInList to do abort change when data is null)

Best regards
Rico


Top
 Profile  
 
PostPosted: 20 Mar 2012, 19:14 
Offline

Joined: 19 Jan 2012, 20:54
Posts: 12
May be this variant:
Code:
procedure DataSet1BeforePost(DataSet: TDataSet);
begin
  if DataSet1.FieldByName('CheckField').IsNull then
    begin
      ShowMessage('Error ...');
      Abort;
    end;
end;


Top
 Profile  
 
PostPosted: 20 Mar 2012, 20:41 
Offline

Joined: 09 Feb 2012, 17:05
Posts: 124
Thank you sinys,

With this, you don't have null value and you have a message, but it's not better than set required on the field
The user can input bad values and I think that the control should be in the column before the post data ...

In the same idea, want that user can input only the values of the comboBox on a lookupField is logical too

Only Dmitry can say if it's a good idea or not ... ;)

Rico


Top
 Profile  
 
PostPosted: 20 Mar 2012, 22:02 
Offline
Администратор

Joined: 22 Dec 2011, 20:19
Posts: 335
Hello Rico.

About TField.Required.
Suppose the end user don't even enter the cell where you require to enter value.
And he will try to post changes. How any property in the column could help you to force to enter value if user even didn't put input cursor to that cell?

if you set TField.Required then
When the dialog about a field that must have a value is shown and you press Escape or Enter The DataSet is still in the Inserting mode, so all your values entered in over fields don't lose yet.
You can move cursor to the offered field, enter a value and post a record.

_________________
Best regards
Admin


Top
 Profile  
 
PostPosted: 21 Mar 2012, 02:24 
Offline

Joined: 09 Feb 2012, 17:05
Posts: 124
Hello Dmitry,

I see that you don't understand what I need, so I'll give you a real example of my application.

First there are two properties to add on TDBColumnGridEh, not one

1 - AllowNullValue (True/False)

With this propertie the field value can be null, but when a value is set, the user have only the choice to change the value with the comboBox or input a new value.
In this case VK_DELETE does nothing and an empty string is not valid

2 - AllowNewValue (True/False)
With this property the field can be null too, but the user have only the choice to change the value with the comboBox
In this case TDBColumnGridEh works like a classic comboBox

Example 1 : Input invoice lines

My record is like this : lineType, product code, product name, quantity, price, V.A.T ...

The field V.A.T (Value added tax) is required for product line
When the I add a product in the invoice the V.A.T have a value (this value is required in the table product)
The user can change the V.A.T with a comboBox, but in never case can set value to null (even if V.A.T equal 0, in this case V.A.T 0% must exists) and he can't add a new TAX.

In this invoice, I can add differents type of lines as comments by example, and in this case the field V.A.T is null, I use only the product name and the type of line.

With the event OnGetParams I set readOnly to True for such lines on V.A.T and all work fine...

As you can see, I can't set required = True on the field V.A.T

Actually, the user can set Null in this field, but with the property AllowNewValue = False and AllowNullValue = False, no error is possible

Example 2 : Add criteria on product

In this case the user can choose criteria with the comboBox and can add a new element when it doesn't exists in the list.
When a add a new criteria, the field is null, so if the user don't choose a criteria, the record is not posted.
But the user can select an other criteria, but in never case set a null value.

Actually, the user can set Null in this field, but with the property AllowNullValue = False, no error is possible

Hope you are agree with me :)

Thank you

Best regards
Rico


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group