Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

maxLength against a TDBComboBox

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm using a TDBComboBox in one of my forms.
I set up the list of Items dynamically.
The TDBCombobox has its DataSource pointed to a TDataSource connected to a TQuery that has RequestLive = True.
The Item String selected can be of a length longer than that of the target field so when I save (post) the entry my string is truncated.
In order to resolve this I've been attempting to make use of a TDBEdit on top of a TDBComboBox such that when the user selects an entry in the TDBCombobox the entry is seen in the TDBEdit.
Ideally I want to prevent this string trucation without using the TDBEdit as the middle-man in this situation.
How can I use the component to prevent a string of longer length being fed ?
Steve
 
You could write something along these lines in the onchange event to stop the number of charcters (in this case) exceeding 20.

var
Temp : String;
begin
if DBComboBox1.GetTextLen > 20 then
begin
Temp := DBComboBox1.Text;
Delete(Temp ,21,100);
DBComboBox1.Text := Temp;
end;
end;

Note that I havent actually tested this code!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top