From Clomosy Docs

(Created page with "Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection. Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.<br> AddNewComboBox(TComponent,xName) : TClComboBox <span style="color:blue"> TComponent</span> : The variable name of the defined...")
 
No edit summary
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection. Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.<br>
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function AddNewComboBox(AComponent: TCLComponent; xName: string): TclComboBox;
</div>


AddNewComboBox(TComponent,xName) : TClComboBox
<span style="color:blue"><b>AComponent</b></span> : Specifies the parent of the object to be defined.<br>


<span style="color:blue"> TComponent</span> : The variable name of the defined component is written. Here you should write the component variable name of whatever your component will be in.
<span style="color:blue"><b>xName</b></span> : The name of the defined combobox should be written.<br>


<span style="color:blue"> xName</span> : The name of the defined combobox should be written.
Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection.<br>


Let's create a combobox.<br>
Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.<br>


1. Create a new project.<br>
<div class="table-responsive">
{| class="wikitable" style="border: 2px solid #c3d7e0"
! style="background-color: #c3d7e0"| Feature  !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
|-
|TClComboBox || ComboBox1 : TClComboBox; || A variable belonging to the TClComboBox class is created.
|-
|AddNewComboBox ||ComboBox1 = Form1.AddNewComboBox(Form1,'ComboBox1'); || A new ComboBox is added to the form.
|-
|AddItem || ComboBox1.AddItem('key1','value1'); ||In order to add data to the list in the Combobox, we need to use "AddItem". You must write the key value in the first parameter in the "AddItem" definition. This is the area you want to appear on the screen. You should write the value it will hold in the second parameter.
|-
|ItemIndex || ComboBox1.ItemIndex || Specifies the index of the selected item. That is, it determines which element is selected.
|-
|GetValueIndex ||ComboBox1.GetValueIndex(ComboBox1.ItemIndex);||Returns the value of the selected string. In other words, it returns the value1 of the field defined by saying ComboBox1.AddItem('key1','value1').
|-
|GetItemIndex ||ComboBox1.GetItemIndex(ComboBox1.ItemIndex) ||Returns the key of the selected string. In other words, it returns the key1 value of the field defined by saying ComboBox1.AddItem('key1','value1').
|-
|Items ||ComboBox1.Items[ComboBox1.ItemIndex]; || This does the same thing as the GetItemIndex definition above.
|-
|Count ||ComboBox1.Items.Count; <i>(Integer)</i> || It is used to check whether the content of the object is empty. This feature is useful for determining whether the object contains any items.
|-
|Width ||ComboBox1.Width = 150; ||Allows the width of columns to be adjusted.
|-
|Height ||ComboBox1.Height = 50; ||llows the height of columns to be adjusted.
|-
|Align ||ComboBox1.Align = alTop; ||With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the [[Object_Properties#Align | page]] to learn about these features.
|-
|Margins || ComboBox1.Margins.Left = 50; // Right, Top, Bottom || With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
|-
|Clear ||ComboBox1.Clear; ||The Clear method is used to clear the elements of a TclComboBox component.
|}
</div>


2. You need to define TClComboBox on the form. To do this, you should add under the ''var'' parameter on the ide as follows. It is the name of your variable you typed at the beginning. You should define this as you want and add it as TClComboBox.<br>
'''var'''
testCombo : TClComboBox;


3. Add the TClComboBox to the form. For this, you must add the begin end block and add it inside the form after the form is defined. By saying MyForm.AddNewComboBox, we actually add to the form we have defined. Here, you need to add your form definition as whatever you wrote it.<br>
<b>Example</b><br>


testCombo := ''MyForm''.AddNewComboBox(MyForm,'testCombo');
Now let's make an example where we can show the value of the selected one in the message box when we select and select one of the days.<br>


4. If you do not want to define it in the form, you can add it in another component (such as Layout, Panel). Of course, before that, that component must be defined.
<pre>
  <span style="color:blue">testLayout</span> := MyForm.AddNewLayout(MyForm,'testLayout');
var
  testCombo:= MyForm.AddNewComboBox(<span style="color:blue">testLayout</span>,'testCombo');
  MyForm:TclForm;
  testCombo : TClComboBox;
testLabel :TClLabel;


5. While defining the component, you can define it manually by typing. Another method is to write its shortcut. If you type "AddNewComboBox" while the shortcut is in the code block, a pop-up menu will appear.<br>
void ComboSelected;
var
[[File:TclComboBoxShortcut.png|frameless|300px]]<br><br>
  strValue,strKey,strKey2 : String;
{
  strValue = testCombo.GetValueIndex(testCombo.ItemIndex);
  strKey = testCombo.GetItemIndex(testCombo.ItemIndex);
  strKey2 = testCombo.Items[testCombo.ItemIndex];


As soon as you click, the following block will come automatically.<br>
  ShowMessage('strValue : '+strValue); //value1
  ShowMessage('strKey : '+strKey); //key
  ShowMessage('strKey2 : '+strKey2); //key
  ShowMessage('testCombo.ItemIndex : '+IntToStr(testCombo.ItemIndex)); //index
}


  AddNewComboBox(xOwner:TComponent; xName:String);
{
  MyForm = TclForm.Create(Self);


6. In order to add data to the list in the Combobox, we need to use "AddItem". You can see the definition below. You must write the key value in the first parameter in the "AddItem" definition. This is the area you want to appear on the screen. You should write the value it will hold in the second parameter.
testLabel= MyForm.AddNewLabel(MyForm,'testLabel','Select the day');
testLabel.Align=alMostTop;
testLabel.StyledSettings = ssFamily;
testLabel.TextSettings.FontColor = clAlphaColor.clHexToColor('#820000');
testLabel.TextSettings.Font.Size=20;
testLabel.Width = 150;
testLabel.Height = 25;
testLabel.Margins.Top=50;
testLabel.Margins.Left =50;
testLabel.Margins.Right =50;


  testCombo.'''AddItem'''('key1','value1');
  testCombo = MyForm.AddNewComboBox(MyForm,'testCombo');
testCombo.Align = alTop;
testCombo.Width = 150;
testCombo.Margins.Top=10;
testCombo.Margins.Left =50;
testCombo.Margins.Right =50;


7. We gave the variable name while defining the TClComboBox in var. Now when you add this in begin end you should use this variable name in all definitions. Your code will throw an error when you write these variable names incorrectly.
testCombo.AddItem('Monday','01');
testCombo.AddItem('Tuesday','02');
testCombo.AddItem('Wednesday','03');
testCombo.AddItem('Thursday','04');
testCombo.AddItem('Friday','05');
testCombo.AddItem('Saturday','06');
testCombo.AddItem('Sunday','07');


8. Now let's design our TClComboBox component. Let's set the width and height first. For this, you must make the following definitions.
  MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected');
 
  MyForm.Run;
testCombo.Height := 50;
}
testCombo.Width := 150;
</pre>
 
9. With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the [https://www.docs.clomosy.com/index.php/Object_Properties#Align page] to learn about these features. We're going to call it the top part here. So we have to write "AlTop".
testCombo.Align := alTop;
 
10. With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
 
testCombo.Margins.Left:= 50;
testCombo.Margins.Right:= 10;
testCombo.Margins.Top:= 50;
testCombo.Margins.Bottom:= 10;
 
[[File:TclComboBoxMargins.png|frameless|400px]]<br><br>
 
11. To tell you the truth, you have created a simple application that does nothing yet. Let's save and start using our project. You can save in one of two ways:<br>
Click the save icon (the button in the upper right corner) or press Ctrl + S to save the project and see what you've done on the platforms now.
 
'''Example:'''<br>
Now let's make an example where we can show the value of the selected one in the message box when we select and select one of the days.<br>
'''Code:'''<br>
  '''var'''
  MyForm:TFrmClomosyBasisForm;
  testCombo : TClComboBox;
  testLabel :TClLabel;<br>
  '''procedure''' ComboSelected;
  '''var'''
    str : String;
  '''begin'''
    str := testCombo.GetValueIndex(testCombo.ItemIndex);
    ShowMessage(str);
  '''end;'''<br> 
'''begin'''
  MyForm := TFrmClomosyBasisForm.Create(Self);<br> 
  testLabel:= MyForm.AddNewLabel(MyForm,'testLabel','Select the day');
  testLabel.Align:=alMostTop;
  testLabel.StyledSettings := ssFamily;
  testLabel.TextSettings.FontColor := clAlphaColor.clHexToColor('#820000');
  testLabel.TextSettings.Font.Size:=20;
  testLabel.Width := 150;
  testLabel.Height := 25;
  testLabel.Margins.Top:=50;
  testLabel.Margins.Left :=50;
  testLabel.Margins.Right :=50;<br>  
  testCombo := MyForm.AddNewComboBox(MyForm,'testCombo');
  testCombo.Align := alTop;
  testCombo.Width := 150;
  testCombo.Margins.Top:=10;
  testCombo.Margins.Left :=50;
  testCombo.Margins.Right :=50;<br>
  testCombo.AddItem('Monday','Monday');
  testCombo.AddItem('Tuesday','Tuesday');
  testCombo.AddItem('Wednesday','Wednesday');
  testCombo.AddItem('Thursday','Thursday');
  testCombo.AddItem('Friday','Friday');
  testCombo.AddItem('Saturday','Saturday');
  testCombo.AddItem('Sunday','Sunday');<br> 
  MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected');
  MyForm.Run;
'''end;'''


'''Output:'''<br>
<b>Output:</b><br>
[[File:Combobox.png|frameless|400px]]
[[File:Combobox.png|frameless|400px]]<br>


= See Also =
<h2> See Also </h2>
* [[Components]]
* [[Object Properties]]
* [[Object Properties]]
* [[AddNewEvent]]
* [[AddNewEvent]]
{{#seo:|title=TclComboBox in Clomosy - Clomosy Docs}}
{{#seo:|description=Explore TclComboBox in Clomosy! Build interactive and customizable dropdown menus to enhance your app’s usability and functionality.}}

Latest revision as of 13:04, 24 February 2025

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined combobox should be written.

Combobox is a box that opens in the form of a list. It is used in events such as data listing, data selection.

Its appearance is close to AddNewEdit, but there is an arrow button on the right side that will enable it to open downwards. In this way, when you press the unlock button, you have the chance to choose among the data listed in it.

Feature Use of Definition
TClComboBox ComboBox1 : TClComboBox; A variable belonging to the TClComboBox class is created.
AddNewComboBox ComboBox1 = Form1.AddNewComboBox(Form1,'ComboBox1'); A new ComboBox is added to the form.
AddItem ComboBox1.AddItem('key1','value1'); In order to add data to the list in the Combobox, we need to use "AddItem". You must write the key value in the first parameter in the "AddItem" definition. This is the area you want to appear on the screen. You should write the value it will hold in the second parameter.
ItemIndex ComboBox1.ItemIndex Specifies the index of the selected item. That is, it determines which element is selected.
GetValueIndex ComboBox1.GetValueIndex(ComboBox1.ItemIndex); Returns the value of the selected string. In other words, it returns the value1 of the field defined by saying ComboBox1.AddItem('key1','value1').
GetItemIndex ComboBox1.GetItemIndex(ComboBox1.ItemIndex) Returns the key of the selected string. In other words, it returns the key1 value of the field defined by saying ComboBox1.AddItem('key1','value1').
Items ComboBox1.Items[ComboBox1.ItemIndex]; This does the same thing as the GetItemIndex definition above.
Count ComboBox1.Items.Count; (Integer) It is used to check whether the content of the object is empty. This feature is useful for determining whether the object contains any items.
Width ComboBox1.Width = 150; Allows the width of columns to be adjusted.
Height ComboBox1.Height = 50; llows the height of columns to be adjusted.
Align ComboBox1.Align = alTop; With the Align parameter, you can specify where you want our component to be aligned in the form. This parameter has multiple positioning properties. See the page to learn about these features.
Margins ComboBox1.Margins.Left = 50; // Right, Top, Bottom With the Margins parameter, you can give margins at any scale from the right, left, bottom, top.
Clear ComboBox1.Clear; The Clear method is used to clear the elements of a TclComboBox component.


Example

Now let's make an example where we can show the value of the selected one in the message box when we select and select one of the days.

var
 MyForm:TclForm;
 testCombo : TClComboBox;
 testLabel :TClLabel;

 void ComboSelected;
 var
   strValue,strKey,strKey2 : String;
 {
   strValue = testCombo.GetValueIndex(testCombo.ItemIndex);
   strKey = testCombo.GetItemIndex(testCombo.ItemIndex);
   strKey2 = testCombo.Items[testCombo.ItemIndex];

   ShowMessage('strValue : '+strValue); //value1
   ShowMessage('strKey : '+strKey); //key
   ShowMessage('strKey2 : '+strKey2); //key
   ShowMessage('testCombo.ItemIndex : '+IntToStr(testCombo.ItemIndex)); //index 
 }

{
 MyForm = TclForm.Create(Self);

 testLabel= MyForm.AddNewLabel(MyForm,'testLabel','Select the day');
 testLabel.Align=alMostTop;
 testLabel.StyledSettings = ssFamily;
 testLabel.TextSettings.FontColor = clAlphaColor.clHexToColor('#820000');
 testLabel.TextSettings.Font.Size=20;
 testLabel.Width = 150;
 testLabel.Height = 25;
 testLabel.Margins.Top=50;
 testLabel.Margins.Left =50;
 testLabel.Margins.Right =50;

 testCombo = MyForm.AddNewComboBox(MyForm,'testCombo');
 testCombo.Align = alTop;
 testCombo.Width = 150;
 testCombo.Margins.Top=10;
 testCombo.Margins.Left =50;
 testCombo.Margins.Right =50;

 testCombo.AddItem('Monday','01');
 testCombo.AddItem('Tuesday','02');
 testCombo.AddItem('Wednesday','03');
 testCombo.AddItem('Thursday','04');
 testCombo.AddItem('Friday','05');
 testCombo.AddItem('Saturday','06');
 testCombo.AddItem('Sunday','07');

 MyForm.AddNewEvent(testCombo,tbeOnChange,'ComboSelected');
 MyForm.Run;
}

Output:
Combobox.png

See Also