|
Post by valleyboy on Mar 18, 2021 6:22:00 GMT -5
I want to prevent a user from adding anything to an existing entry in my combobox Is there a way to make an enabled 'combobox' read only?
|
|
|
Post by Walt Decker on Mar 18, 2021 8:19:25 GMT -5
A user can not add anything to a combobox unless you allow it.
If a user types something into the EDIT control of the combobox, parse the combobox array for a match. If it is not found, take no action.
I assume you did not want to disable the combobox.
|
|
|
Post by valleyboy on Mar 18, 2021 9:46:27 GMT -5
Thanks and yes, disabling is not an option. I guess I was looking for a setting that would prevent the end user from either over typing or appending to an entry in the combobox. I can ignore it but prevention would have been better The following solution is pretty neat but not written using Liberty Basic syntax. Do you know if there is there a way of replicating this in LB4/5? It handles it by subclassing the ComboBox to add a ReadOnly property that hides itself when set and displays a ReadOnly TextBox on top containing the same Text: class ComboBoxReadOnly : ComboBox { public ComboBoxReadOnly() { textBox = new TextBox(); textBox.ReadOnly = true; textBox.Visible = false; } private TextBox textBox; private bool readOnly = false; public bool ReadOnly { get { return readOnly; } set { readOnly = value; if (readOnly) { this.Visible = false; textBox.Text = this.Text; textBox.Location = this.Location; textBox.Size = this.Size; textBox.Visible = true; if (textBox.Parent == null) this.Parent.Controls.Add(textBox); } else { this.Visible = true; this.textBox.Visible = false; } } } }
|
|
|
Post by Rod on Mar 18, 2021 10:58:47 GMT -5
'https://alycesrestaurant.com/lbpe/Stylebits%20-%20Comboboxes.html
nomainwin a$(1) = "one" a$(2) = "two" a$(3) = "three" a$(4) = "four" combobox #win.combo, a$(),[doCombo],10,10,120,200 Stylebits #win.combo, _CBS_DROPDOWNLIST, 0, 0, 0 open "Combobox Demo" for window as #win #win "trapclose [quit]" #win.combo "selectindex 1" wait
[quit] close #win end
[doCombo] #win.combo "selection? sel$" notice "You chose ";sel$ wait
|
|
|
Post by valleyboy on Mar 18, 2021 12:20:51 GMT -5
It's good here ain't it? Thanks a bunch Rod, works a treat!
|
|
|
Post by Rod on Mar 18, 2021 13:28:01 GMT -5
Well it is Janet and Alyce and a host of previous supporters you need to thank. I am only the search engine!
|
|