Here's I wrote some code to say binding not means control and data from database, it may be class holds some data
How to bind ComboBox to an array of object?
//This code developed by Ramy Mahrous
//ramyamahrous@hotmail.com
//Its contents is provided "as is", without warranty.
/// <summary>
/// Represents Student object
/// </summary>
public class Student
{
int id;
public int ID
{
get { return id; }
set { id = value; }
}
string firstName;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
string lastName;
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public string FullName
{
get { return firstName + " " + lastName; }
}
public Student(int id, string firstName, string lastName)
{
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
}
/// <summary>
/// Binds collection of students to ComboBox
/// </summary>
public void Bind()
{
Student[] students = new Student[6];
students[0] = new Student(1, "Ramy", "Mahrous");
students[1] = new Student(2, "FCI", "Helwan");
students[2] = new Student(3, "Danny", "");
students[3] = new Student(4, "Serkan", "Sendur");
students[4] = new Student(5, "Scott", "");
students[5] = new Student(6, "adatapost", "Y");
comboBox1.Items.AddRange(students);
comboBox1.DataSource = students;
comboBox1.ValueMember = "ID";
comboBox1.DisplayMember = "FullName";
}
serkan sendur 821 Postaholic Banned Featured Poster
Ramy Mahrous 401 Postaholic Featured Poster
qauaan 0 Newbie Poster
Ramy Mahrous 401 Postaholic Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.