c# beginner help

jiaweiii

Senior Member
Joined
Sep 3, 2013
Messages
812
Reaction score
0
If that's the case, then you will be having a problem finding your actual object among your array right ?

Why not consider the most easiest mapping. Let the selected index in your combo box correspond to the actual array index. That means if "iPhone 6" is at element index 0, then it will be the first item in the combo box when selected would gives the index 0 ? If "Samsung S4" is in the combo box list at element index 5, then it should correspond to the array at element index 5 too.

This approach is simple, but have an issue with ordering. That means I can't sort based on the combo box list without preserving the same order as with the array.

You can use this technique for start. Then explore on how you can insert a non-string object into the ComboBox. Read from http://stackoverflow.com/questions/...g-text-and-value-to-an-item-no-binding-source

my combo bow i did follow the order of the element index . But i just added all the phones at the combo box edit place
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
using stack overflow more their examples seem clearer

If you are using Microsoft technologies, I suggest you start reading their documentation since those information there are the authorities to the technologies.

The API is there, it's not anywhere else, not even your Stackoverflow. Learn to read from the right sources.
 

jiaweiii

Senior Member
Joined
Sep 3, 2013
Messages
812
Reaction score
0
If you are using Microsoft technologies, I suggest you start reading their documentation since those information there are the authorities to the technologies.

The API is there, it's not anywhere else, not even your Stackoverflow. Learn to read from the right sources.
So after i write int index = comboBoxItem.SelectedIndex; and
comboBoxItem.SelectedIndex = index;

i believe i should write the loop or the quantit-1 / 2 at the check stocks area but how do i write it :s11:
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
So after i write int index = comboBoxItem.SelectedIndex; and
comboBoxItem.SelectedIndex = index;

i believe i should write the loop or the quantit-1 / 2 at the check stocks area but how do i write it :s11:

Why would you want to assign index to the ComboBoxItem.SelectedIndex ?

I don't understand your 2nd enquiry.
 

jiaweiii

Senior Member
Joined
Sep 3, 2013
Messages
812
Reaction score
0
Why would you want to assign index to the ComboBoxItem.SelectedIndex ?

I don't understand your 2nd enquiry.
Is there something wrong with my reasoning here :


string[] c = new string[2];
string[] d = new string[2];
string[] admin = new string[] { "SUPERadmin" };
string[] adminpw = new string[] { "SUPERpassw0rd" };




private void buttonSignIn_Click(object sender, EventArgs e)
{
for (int i = 0; i < admin.Length; i++ )
{
string c = admin;
string d = adminpw;

if (c == textBoxUser.Text.ToString() & d == textBoxPass.ToString())
{
textBoxUser.Text = admin;
textBoxPass.Text = adminpw;

MessageBox.Show("Welcome back Admin");
}

keep sign in failed:s11:
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Is there something wrong with my reasoning here :


string[] c = new string[2];
string[] d = new string[2];
string[] admin = new string[] { "SUPERadmin" };
string[] adminpw = new string[] { "SUPERpassw0rd" };




private void buttonSignIn_Click(object sender, EventArgs e)
{
for (int i = 0; i < admin.Length; i++ )
{
string c = admin;
string d = adminpw;

if (c == textBoxUser.Text.ToString() & d == textBoxPass.ToString())
{
textBoxUser.Text = admin;
textBoxPass.Text = adminpw;

MessageBox.Show("Welcome back Admin");
}

keep sign in failed:s11:


https://msdn.microsoft.com/en-us/library/ms173147%28v=vs.80%29.aspx
 

KnightNiwrem

Senior Member
Joined
Jun 1, 2014
Messages
1,057
Reaction score
0
https://msdn.microsoft.com/en-us/library/ms173147%28v=vs.80%29.aspx

No.. I don't think this is it. Java == operator does compare reference rather than values for String. But this is not the case for C#.

https://msdn.microsoft.com/en-us/library/53k8ybth.aspx

I believe even if he use String.equals, his code might still fail - and that is because I have no idea what textBoxPass.toString() is suppose to evaluate to.

In his code, he later assigns values of type String to textBoxPass.Text and textBoxUser.Text. It seems particularly redundant, then, to call textBoxUser.Text.toString().
 
Last edited:

NSforSG

High Supremacy Member
Joined
Nov 17, 2010
Messages
34,250
Reaction score
2
Is there something wrong with my reasoning here :


string[] c = new string[2];
string[] d = new string[2];
string[] admin = new string[] { "SUPERadmin" };
string[] adminpw = new string[] { "SUPERpassw0rd" };




private void buttonSignIn_Click(object sender, EventArgs e)
{
for (int i = 0; i < admin.Length; i++ )
{
string c = admin;
string d = adminpw;

if (c == textBoxUser.Text.ToString() & d == textBoxPass.ToString())
{
textBoxUser.Text = admin;
textBoxPass.Text = adminpw;

MessageBox.Show("Welcome back Admin");
}

keep sign in failed:s11:


Sorry if I confuse you further, but there is a few things I will like to ask.

1. Is there a need to store admin and adminpw in arrays? I assume that there is only 1 admin from your example.
2. Will it be better to store the admin's username and password using the built-in Dictionary class?

just some thoughts I have. :)
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top