U
Uncle Sammy
Hey all,
I am trying to use a Listbox control with two data bindings. I cannot
get the listbox to change the textboxes. Here's the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BindingNotWorking
{
public partial class Form1 : Form
{
public class LicensePlate
{
private string plate;
private int index;
public string PlateNumber
{
get
{
return this.plate;
}
set
{
this.plate = value;
}
}
public int Index
{
get
{
return this.index;
}
set
{
this.index = value;
}
}
public LicensePlate(string _plate, int _index)
{
this.PlateNumber = _plate;
this.Index = _index;
}
}
public class Vehicle
{
private string make;
private string model;
private int year;
private int index;
public string Make
{
get
{
return this.make;
}
set
{
this.make = value;
}
}
public string Model
{
get
{
return this.model;
}
set
{
this.model = value;
}
}
public int Year
{
get
{
return this.year;
}
set
{
this.year = value;
}
}
public int Index
{
get
{
return this.index;
}
set
{
this.index = value;
}
}
public Vehicle(string _make, string _model, int _year, int
_index)
{
this.Make = _make;
this.Model = _model;
this.Year = _year;
this.Index = _index;
}
}
private LicensePlate[] plates;
private Vehicle[] vehicles;
private void InitializeArrays()
{
vehicles = new Vehicle[] {
new Vehicle("Ford", "Mustang", 1969, 1),
new Vehicle("Chevy", "Nova", 1965, 2),
new Vehicle("Dodge", "Van", 1975, 0)
};
plates = new LicensePlate[] {
new LicensePlate("YVX 809", 1),
new LicensePlate("BAD 001", 2),
new LicensePlate("3M TA3", 0)
};
}
private void BindEmAll()
{
this.listBoxPLATES.DataSource = plates;
this.listBoxPLATES.DisplayMember = "PlateNumber";
this.listBoxPLATES.ValueMember = "Index";
this.textBoxMAKE.DataBindings.Add("Text", vehicles,
"Make");
this.textBoxMODEL.DataBindings.Add("Text", vehicles,
"Model");
this.textBoxYEAR.DataBindings.Add("Text", vehicles,
"Year");
this.listBoxPLATES.DataBindings.Add("SelectedValue",
vehicles, "Index");
}
public Form1()
{
InitializeComponent();
this.InitializeArrays();
this.BindEmAll();
}
}
}
I am trying to use a Listbox control with two data bindings. I cannot
get the listbox to change the textboxes. Here's the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BindingNotWorking
{
public partial class Form1 : Form
{
public class LicensePlate
{
private string plate;
private int index;
public string PlateNumber
{
get
{
return this.plate;
}
set
{
this.plate = value;
}
}
public int Index
{
get
{
return this.index;
}
set
{
this.index = value;
}
}
public LicensePlate(string _plate, int _index)
{
this.PlateNumber = _plate;
this.Index = _index;
}
}
public class Vehicle
{
private string make;
private string model;
private int year;
private int index;
public string Make
{
get
{
return this.make;
}
set
{
this.make = value;
}
}
public string Model
{
get
{
return this.model;
}
set
{
this.model = value;
}
}
public int Year
{
get
{
return this.year;
}
set
{
this.year = value;
}
}
public int Index
{
get
{
return this.index;
}
set
{
this.index = value;
}
}
public Vehicle(string _make, string _model, int _year, int
_index)
{
this.Make = _make;
this.Model = _model;
this.Year = _year;
this.Index = _index;
}
}
private LicensePlate[] plates;
private Vehicle[] vehicles;
private void InitializeArrays()
{
vehicles = new Vehicle[] {
new Vehicle("Ford", "Mustang", 1969, 1),
new Vehicle("Chevy", "Nova", 1965, 2),
new Vehicle("Dodge", "Van", 1975, 0)
};
plates = new LicensePlate[] {
new LicensePlate("YVX 809", 1),
new LicensePlate("BAD 001", 2),
new LicensePlate("3M TA3", 0)
};
}
private void BindEmAll()
{
this.listBoxPLATES.DataSource = plates;
this.listBoxPLATES.DisplayMember = "PlateNumber";
this.listBoxPLATES.ValueMember = "Index";
this.textBoxMAKE.DataBindings.Add("Text", vehicles,
"Make");
this.textBoxMODEL.DataBindings.Add("Text", vehicles,
"Model");
this.textBoxYEAR.DataBindings.Add("Text", vehicles,
"Year");
this.listBoxPLATES.DataBindings.Add("SelectedValue",
vehicles, "Index");
}
public Form1()
{
InitializeComponent();
this.InitializeArrays();
this.BindEmAll();
}
}
}