ListBox selected Item changed event : ListBox « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Class Interface
3. Collections Data Structure
4. Components
5. Data Types
6. Database ADO.net
7. Design Patterns
8. Development Class
9. Event
10. File Stream
11. Generics
12. GUI Windows Form
13. Language Basics
14. LINQ
15. Network
16. Office
17. Reflection
18. Regular Expressions
19. Security
20. Services Event
21. Thread
22. Web Services
23. Windows
24. XML
25. XML LINQ
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / C Sharp » GUI Windows Form » ListBoxScreenshots 
ListBox selected Item changed event
ListBox selected Item changed event

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
  private System.Windows.Forms.ListBox lstCustomers;
  public Form1() {
        InitializeComponent();
    lstCustomers.Items.Add(new Customer("A""B", DateTime.Now.AddDays(-10)));
    lstCustomers.Items.Add(new Customer("C""D", DateTime.Now.AddDays(-100)));
    lstCustomers.Items.Add(new Customer("F""G", DateTime.Now.AddDays(-500)));

  }
  private void lstCustomers_SelectedIndexChanged(object sender, EventArgs e)
  {
    Customer cust = (Customer)lstCustomers.SelectedItem;
    MessageBox.Show("Birth Date: " + cust.BirthDate.ToShortDateString());
  }
  private void InitializeComponent()
  {
    this.lstCustomers = new System.Windows.Forms.ListBox();
    this.SuspendLayout();
    // 
    // lstCustomers
    // 
    this.lstCustomers.FormattingEnabled = true;
    this.lstCustomers.Location = new System.Drawing.Point(1212);
    this.lstCustomers.Name = "lstCustomers";
    this.lstCustomers.Size = new System.Drawing.Size(12095);
    this.lstCustomers.TabIndex = 0;
    this.lstCustomers.SelectedIndexChanged += new System.EventHandler(this.lstCustomers_SelectedIndexChanged);
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(308230);
    this.Controls.Add(this.lstCustomers);
    this.Font = new System.Drawing.Font("Tahoma"8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false);

  }


  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}
public class Customer
{
  public string FirstName;
  public string LastName;
  public DateTime BirthDate;

  public Customer() { }

  public Customer(string firstName, string lastName, DateTime birthDate)
  {
    FirstName = firstName;
    LastName = lastName;
    BirthDate = birthDate;
  }

  public override string ToString()
  {
    return FirstName + " " + LastName;
  }
}


           
       
Related examples in the same category
1. Add new item to ListBox (text from TextBox) Add new item to ListBox (text from TextBox)
2. Remove item if one is selected from ListBoxRemove item if one is selected from ListBox
3. Clear all items in a ListBoxClear all items in a ListBox
4. Add Object to ListBoxAdd Object to ListBox
5. List Box click eventList Box click event
6. Set TopIndex to auto scroll ListBoxSet TopIndex to auto scroll ListBox
7. Form with list, buttonForm with list, button
8. ListBox: font and imageListBox: font and image
9. CheckedListBox Demo 2CheckedListBox Demo 2
10. ListBox Demo 2ListBox Demo 2
11. ListBox and Metafile EnumListBox and Metafile Enum
12. ListBox ObjectsListBox Objects
13. Fill XML data to ListBox
w_w_w.ja_va__2_s._c_o_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.