I am sure that someone asked about this before, but I am not looking for the right conditions or something, because I just can not find what I am looking for.
I have a Packages class:
class Packages { string PackageID {get; set;} string PackageName { get; set; } }
I have a list of packages in my context.
public class TransferJobContext { public string ImportFile; public string WorkSheetName; public DataSet TransferData; public List<Packages> Packages = new List<Packages>(); }
I have a checkListBox in my form bound to a data source. Here is the code section where I get the values ββin checkedListBox
using (var connection = my_DB.GetConnection()) { try { connection.Open(); SqlDataReader rdr = null; dt = new DataTable(); string CommandText = "SELECT ID, Name FROM TABLENAME WHERE UPPER(Import_File_Source) LIKE '%abc%' and STATUS = 1"; SqlCommand cmd = new System.Data.SqlClient.SqlCommand(CommandText, connection); rdr = cmd.ExecuteReader(); dt.Load(rdr); cbPackages.DataSource = dt; cbPackages.ValueMember = "ID"; cbPackages.DisplayMember = "Name"; } catch (Exception E) { MessageBox.Show(E.Message.ToString()); } connection.Close(); }
How to add a new package to the list when an item is checked with the value item and displaymember from the selected items?
Edit: Well, maybe I'm completely wrong. Instead of telling you what I did, I will tell you what I would like to do.
I represent my user with a checklistbox that has a list of names with checkboxes next to them. They can choose more than one. This leads to the fact that I have one or more identifiers to use in my request and the name (s) to use as a description. I need to pass one or more id / name combinations of my "Package" with my context.
What is the best way to grab the ID / Name combination from user preferences and pass them into my context?
source share