Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So I made simple calculator using pushbuttons(+,-,*,/)now i want to add a combobox instead of pushbuttons but i dont really now how.I was trying with switch case but it dont work.PLease help.

What I have tried:

I tried switch and i think i can make it with switch but my code is not good.
Posted
Updated 7-Feb-22 2:28am
Comments
OriginalGriff 6-Feb-22 15:44pm    
Start by picking a language and a framework - how you do things is not the same in all languages, nor in all frameworks.
So tag your question with what you are actually using, and not a pile of things that might be relevant to you.

Then remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with - we get no other context for your project. So show us the relevant code fragments, and explain what it does that you didn't expect or doesn't do that you did.

Imagine this: you go for a drive in the country, but you have a problem with the car. You call the garage, say "it broke" and turn off your phone. How long will you be waiting before the garage arrives with the right bits and tools to fix the car given they don't know what make or model it is, who you are, what happened when it all went wrong, or even where you are?

That's what you've done here. So stop typing as little as possible and try explaining things to people who have no way to access your project!

Use the "Improve question" widget to edit your question and provide better information.
Elmin Hozbo 6-Feb-22 15:55pm    
I just dont now how to make my combobox calculate two numbers when i click calculate button.It is just that.
Ali Al Omairi(Abu AlHassan) 7-Feb-22 5:56am    
I think you can use the SelectedText property
merano99 6-Feb-22 18:43pm    
You tagged the Question with many Tags: C++, C#, QT
The techniques are not compatible and, moreover, one could propose a solution with Win32 or MFC or .NET for C++ alone. It is best to show the existing code and only use tags for techniques that should also be used.
There is not enough information to be able to help here.
Ali Al Omairi(Abu AlHassan) 7-Feb-22 5:53am    
Elmin, you made your application with c# windows form, right?
can you post your code so i can see what is wrong with it?

Try some searching with a search machine which spitted out some QT5 TUTORIAL QCOMBOBOX - 2020.
 
Share this answer
 
//C# Windows Form, when working with ComboBox, you have to assign DataSource, ValueMember to access the id of selected text and DisplayMember to show the selected text. You can achieve this using the following code:
public class Operator
{
      public string Id { get; set; }
      public string Sign { get; set; }
}
IList<Operator> Operators = new List<Operator>();
Operators.Add(new Operator() { Id = "1", Sign = "+" });
Operators.Add(new Operator() { Id = "2", Sign = "-" });
Operators.Add(new Operator() { Id = "3", Sign = "*" });
Operators.Add(new Operator() { Id = "4", Sign = "/" });

comboBox.DataSource = Operators;
comboBox.ValueMember = "Id";
comboBox.DisplayMember = "Sign";
//SelectedValue will return the selected value Id and SelectedText will return Text.
switch (comboBox.SelectedValue) 
{
    case "1": //+
        // You will get the 'Id' of the selected sign
        break;
    case "2": // -
        // Your Code
        break;
    case "3": // *
        // Your Code
        break;
    case "4": // /
        // Your Code
        break;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900