<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FADO.Net%2FDataBinding_ListBox</id>
		<title>Csharp/CSharp Tutorial/ADO.Net/DataBinding ListBox - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FADO.Net%2FDataBinding_ListBox"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/ADO.Net/DataBinding_ListBox&amp;action=history"/>
		<updated>2026-04-30T00:09:17Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/ADO.Net/DataBinding_ListBox&amp;diff=6474&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/ADO.Net/DataBinding_ListBox&amp;diff=6474&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/ADO.Net/DataBinding_ListBox&amp;diff=6475&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/ADO.Net/DataBinding_ListBox&amp;diff=6475&amp;oldid=prev"/>
				<updated>2010-05-26T12:19:10Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Binding ListBox to a Database table==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
public class ListBoxBindingTable : System.Windows.Forms.Form&lt;br /&gt;
{&lt;br /&gt;
  private System.Windows.Forms.ListBox employeeList;&lt;br /&gt;
  private System.ruponentModel.Container components = null;&lt;br /&gt;
  public ListBoxBindingTable()&lt;br /&gt;
  {&lt;br /&gt;
    InitializeComponent();&lt;br /&gt;
    string connectionString = &amp;quot;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;&amp;quot;;&lt;br /&gt;
    string commandString = &amp;quot;Select ID, FirstName from Employee&amp;quot;;&lt;br /&gt;
    SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, connectionString);&lt;br /&gt;
    DataSet dataSet = new DataSet();&lt;br /&gt;
    dataAdapter.Fill(dataSet,&amp;quot;Employee&amp;quot;);&lt;br /&gt;
    DataTable dataTable = dataSet.Tables[0];&lt;br /&gt;
    employeeList.DataSource= dataTable;&lt;br /&gt;
    employeeList.DisplayMember = &amp;quot;Employee&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  }&lt;br /&gt;
  protected override void Dispose( bool disposing )&lt;br /&gt;
  {&lt;br /&gt;
    if( disposing )&lt;br /&gt;
    {&lt;br /&gt;
      if (components != null) &lt;br /&gt;
      {&lt;br /&gt;
        components.Dispose();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    base.Dispose( disposing );&lt;br /&gt;
  }&lt;br /&gt;
  private void InitializeComponent()&lt;br /&gt;
  {&lt;br /&gt;
    this.employeeList = new System.Windows.Forms.ListBox();&lt;br /&gt;
    this.SuspendLayout();&lt;br /&gt;
    this.employeeList.Location = new System.Drawing.Point(8, 8);&lt;br /&gt;
    this.employeeList.Name = &amp;quot;employeeList&amp;quot;;&lt;br /&gt;
    this.employeeList.Size = new System.Drawing.Size(272, 95);&lt;br /&gt;
    this.employeeList.TabIndex = 0;&lt;br /&gt;
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
    this.ClientSize = new System.Drawing.Size(292, 133);&lt;br /&gt;
    this.Controls.AddRange(new System.Windows.Forms.Control[] {this.employeeList});&lt;br /&gt;
    this.Name = &amp;quot;ListBoxBindingTable&amp;quot;;&lt;br /&gt;
    this.Text = &amp;quot;ListBoxBindingTable&amp;quot;;&lt;br /&gt;
    this.ResumeLayout(false);&lt;br /&gt;
  }&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Application.Run(new ListBoxBindingTable());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Data Binding: ListBox==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Data.OleDb;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
public class ListBoxDataBindingDatabase : System.Windows.Forms.Form&lt;br /&gt;
{&lt;br /&gt;
  private System.Windows.Forms.DataGrid dataGrid1;&lt;br /&gt;
  private System.Windows.Forms.ListBox listBox1;&lt;br /&gt;
  private System.ruponentModel.Container components = null;&lt;br /&gt;
  public ListBoxDataBindingDatabase()&lt;br /&gt;
  {&lt;br /&gt;
    InitializeComponent();&lt;br /&gt;
  }&lt;br /&gt;
  protected override void Dispose( bool disposing )&lt;br /&gt;
  {&lt;br /&gt;
    if( disposing )&lt;br /&gt;
    {&lt;br /&gt;
      if (components != null) &lt;br /&gt;
      {&lt;br /&gt;
        components.Dispose();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    base.Dispose( disposing );&lt;br /&gt;
  }&lt;br /&gt;
  private void InitializeComponent()&lt;br /&gt;
  {&lt;br /&gt;
    this.dataGrid1 = new System.Windows.Forms.DataGrid();&lt;br /&gt;
    this.listBox1 = new System.Windows.Forms.ListBox();&lt;br /&gt;
    ((System.ruponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();&lt;br /&gt;
    this.SuspendLayout();&lt;br /&gt;
    // &lt;br /&gt;
    // dataGrid1&lt;br /&gt;
    // &lt;br /&gt;
    this.dataGrid1.DataMember = &amp;quot;&amp;quot;;&lt;br /&gt;
    this.dataGrid1.Location = new System.Drawing.Point(8, 24);&lt;br /&gt;
    this.dataGrid1.Name = &amp;quot;dataGrid1&amp;quot;;&lt;br /&gt;
    this.dataGrid1.Size = new System.Drawing.Size(192, 232);&lt;br /&gt;
    this.dataGrid1.TabIndex = 0;&lt;br /&gt;
    // &lt;br /&gt;
    // listBox1&lt;br /&gt;
    // &lt;br /&gt;
    this.listBox1.Location = new System.Drawing.Point(216, 32);&lt;br /&gt;
    this.listBox1.Name = &amp;quot;listBox1&amp;quot;;&lt;br /&gt;
    this.listBox1.Size = new System.Drawing.Size(104, 212);&lt;br /&gt;
    this.listBox1.TabIndex = 1;&lt;br /&gt;
    // &lt;br /&gt;
    // ListBoxDataBindingDatabase&lt;br /&gt;
    // &lt;br /&gt;
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
    this.ClientSize = new System.Drawing.Size(480, 277);&lt;br /&gt;
    this.Controls.AddRange(new System.Windows.Forms.Control[] {this.listBox1, this.dataGrid1});&lt;br /&gt;
    this.Name = &amp;quot;ListBoxDataBindingDatabase&amp;quot;;&lt;br /&gt;
    this.Text = &amp;quot;ListBoxDataBindingDatabase&amp;quot;;&lt;br /&gt;
    this.Load += new System.EventHandler(this.ListBoxDataBindingDatabase_Load);&lt;br /&gt;
    ((System.ruponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();&lt;br /&gt;
    this.ResumeLayout(false);&lt;br /&gt;
  }&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Application.Run(new ListBoxDataBindingDatabase());&lt;br /&gt;
  }&lt;br /&gt;
  private void FillDataGrid()&lt;br /&gt;
  {&lt;br /&gt;
    string ConnectionString = @&amp;quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Northwind.mdb&amp;quot;;&lt;br /&gt;
    OleDbConnection conn = new OleDbConnection(ConnectionString);&lt;br /&gt;
    string SQL = &amp;quot;SELECT * FROM Customers&amp;quot;;&lt;br /&gt;
    conn.Open();&lt;br /&gt;
    OleDbDataAdapter adapter = new OleDbDataAdapter(SQL, conn);&lt;br /&gt;
    DataSet ds = new DataSet(&amp;quot;Customers&amp;quot;);&lt;br /&gt;
    adapter.Fill(ds, &amp;quot;Customers&amp;quot;);&lt;br /&gt;
    dataGrid1.DataSource = ds.DefaultViewManager;&lt;br /&gt;
    conn.Close();    &lt;br /&gt;
  }&lt;br /&gt;
  private void FillListBox()&lt;br /&gt;
  {&lt;br /&gt;
    string ConnectionString = @&amp;quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\Northwind.mdb&amp;quot;;&lt;br /&gt;
    OleDbConnection conn = new OleDbConnection(ConnectionString);&lt;br /&gt;
    string SQL = &amp;quot;SELECT * FROM Customers&amp;quot;;&lt;br /&gt;
    conn.Open();&lt;br /&gt;
    OleDbDataAdapter adapter = new OleDbDataAdapter(SQL, conn);&lt;br /&gt;
    DataSet ds = new DataSet(&amp;quot;Customers&amp;quot;);&lt;br /&gt;
    adapter.Fill(ds, &amp;quot;Customers&amp;quot;);&lt;br /&gt;
    listBox1.DataSource = ds.DefaultViewManager;&lt;br /&gt;
    listBox1.DisplayMember = &amp;quot;CustomerID&amp;quot;;&lt;br /&gt;
    conn.Close();    &lt;br /&gt;
  }&lt;br /&gt;
  private void ListBoxDataBindingDatabase_Load(object sender, System.EventArgs e)&lt;br /&gt;
  {&lt;br /&gt;
    FillListBox();&lt;br /&gt;
    FillDataGrid();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Fill ListBox with data from a DataReader==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
public class ListBoxFillFromDataReader : System.Windows.Forms.Form&lt;br /&gt;
{&lt;br /&gt;
    private System.Data.SqlClient.SqlConnection connection;&lt;br /&gt;
    private System.Data.DataSet dataSet;&lt;br /&gt;
    private System.Data.SqlClient.SqlCommand command;&lt;br /&gt;
    private System.Data.SqlClient.SqlDataAdapter dataAdapter;&lt;br /&gt;
    private System.Windows.Forms.ListBox lbBugs;&lt;br /&gt;
  private System.ruponentModel.Container components = null;&lt;br /&gt;
  public ListBoxFillFromDataReader()&lt;br /&gt;
  {&lt;br /&gt;
    InitializeComponent();&lt;br /&gt;
        string connectionString = &amp;quot;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;&amp;quot;;&lt;br /&gt;
    using (connection = new System.Data.SqlClient.SqlConnection(connectionString))&lt;br /&gt;
    {&lt;br /&gt;
      connection.Open();&lt;br /&gt;
      using(dataSet = new System.Data.DataSet())&lt;br /&gt;
      {&lt;br /&gt;
        dataSet.CaseSensitive=true;&lt;br /&gt;
        string commandString = &amp;quot;Select ID, FirstName from Employee&amp;quot;;&lt;br /&gt;
        command = new System.Data.SqlClient.SqlCommand();&lt;br /&gt;
        command.Connection=connection;&lt;br /&gt;
        command.rumandText= commandString;&lt;br /&gt;
        using (SqlDataReader dataReader = command.ExecuteReader())&lt;br /&gt;
        {&lt;br /&gt;
          while (dataReader.Read())&lt;br /&gt;
          {&lt;br /&gt;
            object bugID = dataReader[&amp;quot;ID&amp;quot;];&lt;br /&gt;
            object description = dataReader[&amp;quot;FirstName&amp;quot;];&lt;br /&gt;
            lbBugs.Items.Add(bugID.ToString() + &amp;quot;: &amp;quot; +  description.ToString());&lt;br /&gt;
          }&lt;br /&gt;
        }  &lt;br /&gt;
      }    &lt;br /&gt;
    }      &lt;br /&gt;
    }&lt;br /&gt;
  protected override void Dispose( bool disposing )&lt;br /&gt;
  {&lt;br /&gt;
    if( disposing )&lt;br /&gt;
    {&lt;br /&gt;
      if (components != null) &lt;br /&gt;
      {&lt;br /&gt;
        components.Dispose();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    base.Dispose( disposing );&lt;br /&gt;
  }&lt;br /&gt;
  private void InitializeComponent()&lt;br /&gt;
  {&lt;br /&gt;
        this.lbBugs = new System.Windows.Forms.ListBox();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        this.lbBugs.Location = new System.Drawing.Point(16, 8);&lt;br /&gt;
        this.lbBugs.Name = &amp;quot;lbBugs&amp;quot;;&lt;br /&gt;
        this.lbBugs.Size = new System.Drawing.Size(216, 147);&lt;br /&gt;
        this.lbBugs.TabIndex = 0;&lt;br /&gt;
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
        this.ClientSize = new System.Drawing.Size(264, 181);&lt;br /&gt;
        this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
                                                                      this.lbBugs});&lt;br /&gt;
        this.Name = &amp;quot;ListBoxFillFromDataReader&amp;quot;;&lt;br /&gt;
        this.Text = &amp;quot;ListBoxFillFromDataReader&amp;quot;;&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Application.Run(new ListBoxFillFromDataReader());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Read data from database table add it to a ListBox==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Drawing;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using System.ruponentModel;&lt;br /&gt;
using System.Windows.Forms;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Data.SqlClient;&lt;br /&gt;
public class ListBoxTableReadingFill : System.Windows.Forms.Form&lt;br /&gt;
{&lt;br /&gt;
    private System.Data.SqlClient.SqlConnection myConnection;&lt;br /&gt;
    private System.Data.DataSet myDataSet;&lt;br /&gt;
    private System.Data.SqlClient.SqlCommand myCommand;&lt;br /&gt;
    private System.Data.SqlClient.SqlDataAdapter myDataAdapter;&lt;br /&gt;
    private System.Windows.Forms.ListBox employeeList;&lt;br /&gt;
  private System.ruponentModel.Container components = null;&lt;br /&gt;
  public ListBoxTableReadingFill()&lt;br /&gt;
  {&lt;br /&gt;
    InitializeComponent();&lt;br /&gt;
        string connectionString = &amp;quot;server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;&amp;quot;;&lt;br /&gt;
        myConnection = new System.Data.SqlClient.SqlConnection(connectionString);&lt;br /&gt;
        myConnection.Open();&lt;br /&gt;
        myDataSet = new System.Data.DataSet();&lt;br /&gt;
        myDataSet.CaseSensitive=true;&lt;br /&gt;
        string commandString = &amp;quot;Select ID, FirstName from Employee&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
        myCommand = new System.Data.SqlClient.SqlCommand();&lt;br /&gt;
        myCommand.Connection=myConnection;&lt;br /&gt;
        myCommand.rumandText= commandString;&lt;br /&gt;
        myDataAdapter = new SqlDataAdapter();&lt;br /&gt;
        myDataAdapter.SelectCommand = myCommand;&lt;br /&gt;
        myDataAdapter.TableMappings.Add(&amp;quot;Table&amp;quot;, &amp;quot;Employee&amp;quot;);&lt;br /&gt;
        myDataAdapter.Fill(myDataSet);&lt;br /&gt;
&lt;br /&gt;
        DataTable myDataTable = myDataSet.Tables[0];&lt;br /&gt;
        &lt;br /&gt;
        foreach (DataRow dataRow in myDataTable.Rows)&lt;br /&gt;
        {&lt;br /&gt;
            employeeList.Items.Add(dataRow[&amp;quot;ID&amp;quot;] + &amp;quot;:&amp;quot; + dataRow[&amp;quot;FirstName&amp;quot;]  );&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
  protected override void Dispose( bool disposing )&lt;br /&gt;
  {&lt;br /&gt;
    if( disposing )&lt;br /&gt;
    {&lt;br /&gt;
      if (components != null) &lt;br /&gt;
      {&lt;br /&gt;
        components.Dispose();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    base.Dispose( disposing );&lt;br /&gt;
  }&lt;br /&gt;
  private void InitializeComponent()&lt;br /&gt;
  {&lt;br /&gt;
        this.employeeList = new System.Windows.Forms.ListBox();&lt;br /&gt;
        this.SuspendLayout();&lt;br /&gt;
        // &lt;br /&gt;
        // employeeList&lt;br /&gt;
        // &lt;br /&gt;
        this.employeeList.Location = new System.Drawing.Point(16, 8);&lt;br /&gt;
        this.employeeList.Name = &amp;quot;employeeList&amp;quot;;&lt;br /&gt;
        this.employeeList.Size = new System.Drawing.Size(216, 147);&lt;br /&gt;
        this.employeeList.TabIndex = 0;&lt;br /&gt;
        // &lt;br /&gt;
        // ListBoxTableReadingFill&lt;br /&gt;
        // &lt;br /&gt;
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);&lt;br /&gt;
        this.ClientSize = new System.Drawing.Size(464, 205);&lt;br /&gt;
        this.Controls.AddRange(new System.Windows.Forms.Control[] {&lt;br /&gt;
                                                                      this.employeeList});&lt;br /&gt;
        this.Name = &amp;quot;ListBoxTableReadingFill&amp;quot;;&lt;br /&gt;
        this.Text = &amp;quot;ListBoxTableReadingFill&amp;quot;;&lt;br /&gt;
        this.ResumeLayout(false);&lt;br /&gt;
    }&lt;br /&gt;
  [STAThread]&lt;br /&gt;
  static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    Application.Run(new ListBoxTableReadingFill());&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>