Jump to content

combo box drop down value relation between two tabs

- - - - -

  • Please log in to reply
6 replies to this topic

#1
elizabethmwashuma

elizabethmwashuma

    Newbie

  • Members
  • PipPip
  • 29 posts
i have a login form that contains a combo box and a text box and a button. the items of the como box are from the databse while the person selected can only log into the system if the password he enters on the textbox matches the password details in the database.(of the name selected)

my problem is, the second tab contains a couple of textboxes and combo boxes that need to be filled in. but i want the first combo box in the second tab to have drop down value of the name of the person that has logged in to fill in the form.

the person login in the first tab, his name should appera on the combo box in the second tab

#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
This can all be managed in your code, behind the form

You might consider building an object type to house all the information you want to be available, call it something like user

class User {

    public string Name;

    public string etc;

}


When they log in, you can create an object, and fill in the blanks.

I usually have a section of methods that I call Form Helpers,
ei:


#region [Form Helpers]


void updateform_userlogin(User user) {

    cbxUserTab2.Value = user.whatever;

    txtUserName.Temt = user.Name;

}


#endregion



I personally find it makes the code a log more readable, then you end up with things like this:



private void cmdLogin_Click(object sender, EventArgs args) {

    if ((User logged_in_user = login(txtUsername.Text, txtPassword.Text)) != null) {

        updateform_userlogin(logged_in_user);

    }

}



I mean, that's all pseudo code, but you get the idea. Break it down into units like that, and your logic becomes really english, and all these small ui updating tasks become obvious.

#3
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Umm if the comboBoxes are on the same form why cant she just use:
 comboBox2.Items.Add(comboBox1.SelectedItem);
Inside a _TabIndexChanged event?

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#4
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
no technical reason, and ultimately, something like that might drive the action

but that specific example is more of an exception, than a rule.

it tends to lead to spaghetti-code.

I'd rather see managed and properly named functions encapsulate that type of thing,

so rather than having "when the drop down index changes"

do this

do that

do this other thing


instead have that updating happen when the user is logged in.

so instead your form can then have states, for example, Logged in, Not Logged in
the Logged in state can also have context to a specific user

but ultimately, I don't think you and I are arguing, just talking about a different aspect to a multi-part solution

#5
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
I agree. I think my code would be easiest and faster, but having a class for, as you said logged in, not logged in, username ect would make the code much more managed and easier to work with.
~ Committed. :) +rep.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts

Quote

but ultimately, I don't think you and I are arguing, just talking about a different aspect to a multi-part solution
Oh, of course not! I love learning and discussing new and different ways to optimize and clean up code. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#7
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
Thanks for the rep! =)

Yeah, that's one thing I really like about this forum, good discussions and good company!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users