473,385 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Binding custom business object list using a combo box

Hi, i have a class which has a property which is a list of items. I
want to be able to set this item list from a set of items (in this case
list2 as shown in the code below) from a drop down combo box. This will
allow me to enter valid items in a seperate form, then when adding a
new Class1 object i can select from one of the valid Class2 items in
the dropdown list. I hope this makes sense, i have got partway there
but i have lost synchronisation and i dont think the code is correct. I
have posted some of the code below, and posted the full project source
at www.monsterserve.net/test.zip

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

namespace Test
{
public partial class Form1 : Form
{
static public BindingList<Class1> list = new
BindingList<Class1>();
static public BindingList<Class2> list2 = new
BindingList<Class2>();

public Form1()
{
InitializeComponent();

list2.Add(new Class2("bill"));
list2.Add(new Class2("fred"));

m_Class1BindingSource.DataSource = list;

m_Class2BindingSource.DataSource = m_Class1BindingSource;
m_Class2BindingSource.DataMember = "MyClass";

nameDataGridViewTextBoxColumn1.DataSource = list2;
nameDataGridViewTextBoxColumn1.DisplayMember = "Name";
}
}

public class Class2
{
string m_Name;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}

public Class2(string name)
{
Name = name;
}
}

public class Class1
{
public Class1()
{
m_Class2 = Form1.list2[0];
}

string m_Name;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}

Class2 m_Class2;

public Class2 MyClass
{
get { return m_Class2; }
set { m_Class2 = value; }
}
}
}

I would also like to have a list, where i can use a combobox to select
from a set of valid pre-existing items. I have seen from the book "Data
Binding With Windows Forms 2.0" on chapter 9 it almost does what i want
but there is not preexisting list.

Any pointers much appreciated, with my newb skills i am very stuck!!

Cheers,

Chris

Feb 24 '06 #1
0 2619

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
0
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. ...
0
by: JSantora | last post by:
Essentially, InsertAT is broken! For the past couple of hours, I've been getting this "Parameter name: '-2147483550' is not a valid value for 'index'." error. Apparently, its caused by having...
13
by: Michael.Suarez | last post by:
Let's suppose I have an instance of MyClass, which has the properties MyText1 and MyText2, and sets the values of MyText1 and MyText2 to 'A' and 'B' in it's constructor. Let's also suppose I...
7
by: Nathan | last post by:
I'd like to use an enumeration as a datasource for a drop-down box. Is there a way to do this?
3
by: cannontrodder | last post by:
I am displaying names and other details of my users in a Formview control by binding my custom business object to it. My custom object also has a property that is a collection of boolean values and...
9
by: =?Utf-8?B?VGVycnk=?= | last post by:
Think it is great the way that you can set up a datsource, value member, and display member for a combobox, and map a 'code' to a 'description' and back again by binding the combobox to a...
5
by: =?Utf-8?B?VGVycnk=?= | last post by:
Hi, I have a couple of labels on a form and their visible property is bound to boolean properties on a custom object. When I first load the form, all works as it should. This form is 'tied'...
3
by: jehugaleahsa | last post by:
Hello: First of all, sorry if I leave out some details. I have a bad habit of doing that. Just ask me and I will surely give them to you. I have a Windows Form with a combo box on it. It's...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.