9 Replies - 251 Views - Last Post: 21 June 2019 - 11:17 AM Rate Topic: -----

#1 okaymy1112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 10-June 19

How do I populate a List-box from a database table

Posted 21 June 2019 - 07:44 AM

I have a windows application where I have added a List box AdditionalStaffEmailListBox. I would like to add all emails from a database table when the application runs.
Database Name is StaffEmail and table name is MyEmails.
ListBox name is AdditionalStaffEmailListBox

Please help.
Is This A Good Question/Topic? 0
  • +

Replies To: How do I populate a List-box from a database table

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,464
  • Joined: 12-June 08

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 07:46 AM

What have you tried, thought about, or considered?
Was This Post Helpful? 0
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 617
  • View blog
  • Posts: 4,108
  • Joined: 12-January 10

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:04 AM

seems one might try to create a link to the database
then one might try to create a datatable or dataset with the link
then one might try to bind that data to the drop down list

but who am i to judge
Was This Post Helpful? 0
  • +
  • -

#4 okaymy1112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 10-June 19

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:17 AM

I probably should have included more details on my question. The application is working but there is business need to make a change to it. Currently, a user selects one Requestor (name) from RequestorComboBox. Then the user clicks on EmailButton. The EmailButton sends an email to the Requestor that the user selected from the RequestorComboBox.

The required change is to allow the user to select more than one Requestor and send email to all selected Requestors. I do not think there is a way to make the RequestorComboBox allow selecting more than one Requestor. This is why I am trying to use a ListBox instead.

My goal is that the user will select as many names from the ListBox as needed, then click on EmailButton. Email will be sent to each Requestor that the user selected from the ListBox.

Please me know know your thoughts. How would you approach this problem?

This post has been edited by Skydiver: 21 June 2019 - 02:42 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,464
  • Joined: 12-June 08

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:19 AM

What have you tried?
Was This Post Helpful? 0
  • +
  • -

#6 okaymy1112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 10-June 19

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:22 AM

View PostDarenR, on 21 June 2019 - 08:04 AM, said:

seems one might try to create a link to the database
then one might try to create a datatable or dataset with the link
then one might try to bind that data to the drop down list

but who am i to judge


The application I am talking about is currently working. Pulling data from the database for emails but only sends one email to one Requestor. See the response I sent to the Moderator. The code is lengthy and I am not sure I can post all of it here.
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,464
  • Joined: 12-June 08

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:24 AM

Is this a webform, winform, UWP, DOTCORE Razor page?

What part of cycling through a list box's selected items is giving you trouble?

https://docs.microso...etframework-4.8
Was This Post Helpful? 0
  • +
  • -

#8 okaymy1112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 10-June 19

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:44 AM

View Postmodi123_1, on 21 June 2019 - 08:24 AM, said:

Is this a webform, winform, UWP, DOTCORE Razor page?

What part of cycling through a list box's selected items is giving you trouble?

https://docs.microso...etframework-4.8

This is a Windows form. Here is the class
public partial class HomeForm : Form
{


I am not sure how to add the code to select data from the database table and populate my ListBox.
private void AdditionalStaffEmailListBox_SelectedIndexChanged(object sender, EventArgs e){}

Also when I run the code in Debug Mode, the Form loads fine. The only problem is that all buttons, drop down menus etc are disabled and I cannot click on them. I do not know if this has something to do with the Application Config file. The guy who wrote this app left. It is not a web app and it currently run on another guys machine to process emails.
The app config has the following settings
<appSettings>
   <add key="ServiceUri" value="http://localhost:59706/" /><!-- I do not know if I need to change this port 59706 or what to change it to-->
   <add key="ServiceReturnType" value="application/json"/>
</appSettings>
:code:

This post has been edited by modi123_1: 21 June 2019 - 08:54 AM
Reason for edit:: In the future, please highlight the text that is code and click the [code] button in the editor.

Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15113
  • View blog
  • Posts: 60,464
  • Joined: 12-June 08

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 08:53 AM

Like the bulk of the data driven GUI controls - listbox has a spot for 'data source' and you can set the 'display member' and 'value member' for that.

Check the docs:
https://docs.microso...etframework-4.8
https://docs.microso...control-to-data

As for why things are disabled - no clue. Haven't seen the project enough to know what is going on or what the other guy did.
Was This Post Helpful? 0
  • +
  • -

#10 okaymy1112   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 10-June 19

Re: How do I populate a List-box from a database table

Posted 21 June 2019 - 11:17 AM

Thank you for your help. I will try what you suggested. I found out why the from is disabled. It is because I am not in the group that for this particular app. I have requested to be added to this group.

This post has been edited by Skydiver: 21 June 2019 - 02:42 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1