Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void getcategorynames()
- {
- var categorytypes = (from categories in age.categories
- select categories.category_Name).ToList();
- foreach (string item in categorytypes)
- {
- listcategories.Items.Add(item);
- }
- age.Categories.ToList().ForEach((c) => listcategories.Items.Add(c));
- Category category = (Category)listcategories.SelectedItem;
- // Do something with category.Id
- private void getcategorynames() {
- age.Categories.ToList().ForEach((c) => listcategories.Items.Add(c));
- listcategories.SelectedIndexChanged += (sender, e) => {
- Category category = (Category)listcategories.SelectedItem;
- // Do something with category.Id
- };
- }
- public class Cat
- {
- public int Id { get;set;}
- public string Name { get;set;}
- public override string ToString()
- {
- return this.Name;
- }
- }
- private void getcategorynames()
- {
- var categorytypes = (from categories in age.categories
- select categories.category_Name).ToList();
- listcategories.SelectedIndexChanged += new EventHandler(listcategories_SelectedIndexChanged);
- foreach (var c in categorytypes.select(p=> new Cat { Id = p.category_Id, Name = p.category_Name}))
- {
- listcategories.Items.Add(c);
- }
- void listcategories_SelectedIndexChanged(object sender, EventArgs e)
- {
- Cat selected = (Cat)(sender as ListBox).SelectedItem;
- }
- DataTable table = new DataTable();
- public Form1()
- {
- InitializeComponent();
- //you fill the table from database, I will show you my example (becuase I dont have dataBase)!
- table.Columns.Add("CategoryID", typeof(int));
- table.Columns.Add("CategoryName", typeof(string));
- table.Rows.Add(1, "name 1");
- table.Rows.Add(2, "name 2");
- table.Rows.Add(3, "name 3");
- listBox1.DataSource = new BindingSource(table, null);
- listBox1.DisplayMember = "CategoryName";
- listBox1.ValueMember = "CategoryID";
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (listBox1.SelectedIndex > -1)
- {
- DataRowView data = listBox1.SelectedItem as DataRowView;
- int id = int.Parse(data["CategoryID"].ToString());
- string name = data["CategoryName"].ToString();
- }
- }
- class Group
- {
- private string _name;
- private string _id;
- public Group(string name, string id)
- {
- _name = name;
- _id = id;
- }
- public override string ToString()
- { return _name; }
- public string id
- {
- get { return _id; }
- }
- public string name
- {
- get { return _name; }
- }
- }
- lbAvailableGroups.Items.Add(new Group(ds.Tables[0].Rows[i][1].ToString(), ds.Tables[0].Rows[i][0].ToString()));
- }
- Group p = (Group)lbUserGroups.SelectedItem;
- int GroupId = Convert.ToInt32(p.id);
- string GroupName = p.name
Add Comment
Please, Sign In to add comment