Welcome back.
All right.
Now let's go to the logic.
So as you've seen earlier, we can add a logic directly in our code behind file, which is this CSS
file.
And in the main window is where everything starts.
And well, basically what I'm going to add is a bunch of code to my main window, but I'm going to also
have to implement those methods a little more because right now they look pretty empty.
Okay.
So what I need is I need to bind values to my combo boxes.
Okay.
So I have these combo boxes here, this one and this one where the user can select the value from.
Okay.
So you click on it and it displays you the different values and then you can select one of those.
And basically they will be defined as the sitting active value for that combo box.
So in order to use it, I need to make sure that I'm binding a value to it.
So I'm going to create this method which I'm going to call.
Bind.
Currency.
Okay, so this is the new method that we're using here bind currency and it doesn't return anything
here.
So it's void.
So in here I'm going to use a data table.
So I'm going to create a new data table, which I'm going to call data table currency, which will be
a new data table object.
Okay.
So in case data table doesn't appear for you, make sure that you have system data.
Here at the very top using System.data.
Otherwise it won't work.
So you need to have this namespace there.
And now this data table is going to be the data source that I want to or the item source that I want
to define for my combo box from currency.
Okay, that will make sense in a second.
So when you create a data table, you can add columns to it.
So I'm going to add a column to this currency.
So columns, dot add and the first one will be called text.
And then currency columns dot add and the second column will be a value.
Okay, So basically I'm creating a table here and that table has two columns and the rows that will
be in there is what I'm going to add now.
So I'm going to add a bunch of rows that should be inside of that data table.
So the first one should be select and Select has the text of select and the value of zero.
So then the second row that I enter is going to have Indian rupees as the value of one, then US dollars
as €75 as 85.
And then this pound, I'm not sure what pound did was when I decided to add that there, but it's definitely
not British pound.
So you can see we have different values here or different currencies.
Now you could of course go ahead and use very different currencies here and define US dollars as one
and then make sure that you're using the other currencies as for example, or in my case, it would
be euros as one and the US dollars is at 119, for example.
So whatever the current currency exchange rate is, you would add that here.
Okay, so I'm using zero for this one because well, basically the select is a default value where the
user is displayed that he can select something and zero would just multiply with zero.
Okay.
So what I can do now is I can go ahead and say that the combo box that we have be from currency should
use this data table as the item source.
Okay.
So items source should be currency dot.
Default view.
So by doing that, you assign this data table to be the item source for RCMP currency.
Okay, So let me call this bind.
Currency here.
Inside of my main window for this to be executed because otherwise it will never be executed and it
just won't do anything.
Now, by the way, you need to also make sure that you.
Add another line here which says display member path.
So what should it display?
Well, it should display the text and then you need to define what should be the value.
So what should be the underlying value for that particular combo box.
And that should be the value path should be our value column.
Okay.
So selected value path should be value.
And then finally, you can say what the default select index is for your CNB from currency.
So the selected index will be zero.
Let me run that real quick and that will make a little more sense.
So you can see now we have this select here and once I click on it, you can see I have these different
names.
So these different text that is in my column text here.
And it is this because that's what I defined here as the display member path.
It should display the text and what value should be behind it.
Well, it should be the value and that will be whatever value we have here because that's the second
column.
If I had a third column, let me just show you real quick.
Let's say I had the third column and I called this column.
Temperature.
Okay.
Just as an example, then I would have to add another value here.
So let's say in Indian Rupees it's set to one and the temperature is going to be 35 degrees.
So even though it doesn't really make sense, but that's how it would work technically.
Okay.
All right.
So that is basically what I have here.
And you see, the selected index is zero, which means it's going to be the select here.
If I set it to one, let me run it again.
Then it will be automatically set to I and R so to Indian rupee instead of select.
Okay, so that's basically what you have here is basically the starting default value of your combo
box.
Okay.
And now.
Let's do the same thing for our other combo box.
So what is the other combo box that is here is talking about?
Well, it's this one here.
Where is it?
It's let's just click on it here.
This combo box.
And what's the name of the combo box?
It's called CNB two Currency.
So you could have called it however you wanted, right?
This name is free to you, but I called it CNB two currency.
So how do I access it?
Well, with CNB two currency.
And now I need to also give it an item source.
So I'm going to set the item source to be also currency dot default view because it should use the same
data source or data table as the item source and so forth.
Okay.
So I also need to assign the display member path as well as the selected value path as well as the selected
index.
Okay.
So now it's done for the different.
Combo boxes that we have here.
Now what should happen once I click on this convert Click?
Of course, I don't just want to display Hello button clicker.
I want to display something more complex.
I want to display some useful values here.
So let me just copy the code here because.
Otherwise it's going to take forever for me to type all of that in.
Okay.
So when I click on this button, first of all, I want to have a double variable called converted value.
Then I'm checking if the text currency text is null.
Or the text currency text is empty.
It should display a message box saying please enter currency and then information.
Then we have the okay button as well as the message box information, and the focus should be set to
text currency and return.
So let's just try that.
Okay.
What is this message box that happens to appear here?
Well, let me click on Convert.
Well, it didn't implement it yet.
Now let's just run this code and test it.
So let's see.
So you see, this is the message box that appears so with this information, which is this name here
at the top.
And then it says, please enter currency.
And we have one button, which is the okay button, which is amazing.
So I have this message box, which is very basic message box.
It just has one button, which is the okay button.
And yeah, basically that's what we just saw.
And the text currency.
Variable.
This field, which is this text box, is then set to be the focus.
Okay, So you can let me click somewhere else.
Okay.
So let me click in here.
For example, you can see the text is not currently the focus.
Now let me click on Convert.
This window pops up.
I click okay and you can see now the focus is on that text field here.
So that means I can directly enter a value here.
Of course I can enter non numbers as of now and if I try to convert them and well, let's select stuff
here and convert it, you will see our program will crash at that point.
That of course is not what we wanted, so we will still need to fix that.