delphi comboBox - delphi

how does one get the picked value of a combo box from delphi 7
lets say it has items, how does one know which row (item) was picked?

You find the selected item with:
combobox.ItemIndex; // -1 if none
You can get the value using
combobox.Items[combobox.ItemIndex]

combobox.text will hold the value which was selected

When you want to use combobox.text, i recommend to set style to csDropDownList and ItemIndex to 0 in object inspector to have combobox initialized.

Related

Firemokey ComboBox PosSource

In Firemonkey by using ComboBoxes I set the displayed item with the following row:
ComboBoxSomething.ItemIndex := ComboBoxSomething.Items.IndexOf(VarToStr(Query.FieldValues['fieldname']));
There is a BindListLink PosSource binding where the controls ItemIndex+1 binded to the Bindsource's Recno.
However it works only when I change the Combobox selected text by cliking on it, and does nothing when I set the ItemIndex with the code above.
Do you have any suggestion, what to do different?
Thank you in advance!
Endre
Ok, I've got it. At the same time I have to set the RecNo of the query as well (Query.Recno := ComboBox.ItemIndex+1;).
But I still don't know, why it isn't set automatically by the livebinding.

How do i assign a RadioButton to a RadioGroup in XE2?

Don't hate (or devote) me on this silly question, but i noticed on XE2 it has changed, i try to drop a new RadioButton to a RadioGroup and i notice it is actually NOT a part of that group, why ?
and what is this TStrings i need to write ? it's kind of hard for me to control it like that.
You cannot manually add a TRadioButton to a TRadioGroup. The TRadioGroup control has always worked in this way. You must use its Items property to add the radio buttons.
The Embarcadero documentation says
To add radio buttons to a TRadioGroup, edit the Items property in the
Object Inspector. Each string in Items makes a radio button appear in
the group box with the string as its caption. The value of the
ItemIndex property determines which radio button is currently
selected.
So you can use the Object Inspector to edit the Items property or writing code like this:
RadioGroup1.Items.Add('Option 1');
RadioGroup1.Items.Add('Option 2');
RadioGroup1.Items.Add('Option 3');
RadioGroup1.Items.Add('Option 4');
RadioGroup1.Items.Add('Option 5');
Finally to check which radio button is selected use the ItemIndex property like so
if RadioGroup1.ItemIndex>=0 then
ShowMessage(RadioGroup1.Items[RadioGroup1.ItemIndex]);

SmartGWT ComboBoxItem - item in Combo is not marked in the pick list

I'm using ComboBoxItem(com.smartgwt.client.widgets.form.fields.ComboBoxItem). My question is how to force it to mark, hilight selected value in a pick list?
It is demonstrated in the SmartGWT showcase, Combo with a Label "A simple ComboBoxItem" http://www.smartclient.com/smartgwt/showcase/#styled_combobox_category.
'Mouse' item is in the combo, however in the pick list 'Cat' item is selected - not as I would expect - a 'Mouse'.
Thanks in advance,
emph
You can't. ComboBoxItem's PickList object (the drop down list), always moves its cursor (the selection marker) at the top of the list, or the first element that will be selected based on the user's input. If you want the cursor to show the selected value, use the SelectedItem instead, in the same way you use the ComboBoxItem. One drawback with this, is the fact that you can't type and have the auto-complete effect. However, if you type after you open the PickList for the SelectItem, the cursor will move to a matching option.

TStringGrid - is there a simple way to get the "current/selected" row?

I can go the long way round, loop over each row, get a TRect from CellRect(col, row), then query its State for gdSelected ...
But isn't there a quicker way to get the row number of the currently selected row, if any?
.Row for selected row, .Col for selected column
Please have a look at TStringGrid.Row.
With FMX, I'm using StringGrid1.Selected, but I changed property >> Options > RowSelect = true

Which radio button is selected in a TRadioGroup?

As you can see in my question history, I'm developing a eBook manager, that will be open-source and I will release it in about 10 days, but I have a TRadioGroup, as you can see:
TRadioGroup Used On My Form http://img85.imageshack.us/img85/1830/radiogroup.png
And I want to store somethings in a variable(that needs to be a Integer) that will be "linked" with this TRadioGroup.
I need to do a if function like this:
Caption Of The TRadioButton -> Number that will need to be stored in the variable
Fit 2xWidth - Default -> 0
Fit 2xHeight -> 1
Fit Width -> 2
Fit Height -> 3
But I just used a TRadioGroup and a TRadioButton one time, different than in C# that I've used more than 20 times. Then I want to know what I need to put on the if function, because what it will do I already know how to do:
var
num: Integer;
begin
if(TRadioButton1 checked?)
begin
num := 0;
end;
end.
What I need to put inside the brackets of the if function?
PS: I'm going to put the credits on the program for the people that helped me in this little project.
A TRadioButton has the Checked property. But A TRadioGroup has the ItemIndex property.
The items in a TRadioGroup are stored using a TStrings. So you can associate an object to each option and you can cast an integer to a TObject to be stored.
Example:
// fill the radiogroup
radiogroup.Items.AddObject('Fit 2xWidth', TObject(0));
radiogroup.Items.AddObject('Fit 2xHeight', TObject(1));
radiogroup.Items.AddObject('Fit Width', TObject(2));
radiogroup.Items.AddObject('Fit Height', TObject(3));
radiogroup.ItemIndex := 0;
To read the current setting:
value := radiogroup.ItemIndex;
Or to get the associated integer:
index := radiogroup.ItemIndex;
Assert(index>=0); // Sanity check
value := Integer(radiogroup.Items.Objects[index]);
In your case, the values are 0 to 3 so you can use the ItemIndex.
As a note, if is not a function. A function is a piece of code that returns a value based on the input parameters. If is a statement, which is a command that can be executed. The if statement is special because it enables you to execute a different statement based on the if condition.
Just a little TIP: Setting .ItemIndex does not send keyboard focus to the radio item, i know how to fix it, read ahead.
Instead of selecting by code a Radio in a RadioGroup by setting .ItemIndex it is much better to do it by sending focus to the radio item; just to be very clear: i mean sending focus just to the radio item, not the whole radio group.
Instead of: radiogroup.itemindex:=TheIndex;
Do it as this: TRadioButton(radiogroup.Controls[TheIndex]).SetFocus;
It will make the radio item to be selected and send the keyboard focus to it, so it will display the dotted rectangle arroud it, just as if the user had clicked on it.
Note1: To see it in action use keyboard cursor keys and compare behavor of just setting .ItemIndex and sending focus to radio item.
Note2: If you use TRadioButton(radiogroup.Controls[TheIndex]).SetFocus; then there is no no need to set .ItemIndex at all, it will also be done.
Hope that helps someone having the same problem as me, when need to set it by code, for example to avoid circular keyboard behavor, for example for making it to stay on last radio item when last radio item is selected and keyboard right cursor is pressed, same for first.

Resources