473,793 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

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

public Form1()
{
InitializeCompo nent();

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

m_Class1Binding Source.DataSour ce = list;

m_Class2Binding Source.DataSour ce = m_Class1Binding Source;
m_Class2Binding Source.DataMemb er = "MyClass";

nameDataGridVie wTextBoxColumn1 .DataSource = list2;
nameDataGridVie wTextBoxColumn1 .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 2634

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

Similar topics

19
2348
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 object to databind to text boxes etc? I can't use a dataset as the object has loads of derived logic, for example updating one property may actually update several database fields for example.
0
1533
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. There are cases where properties of one object is dependant on a property of another object. For a common example, when you bind an ArrayList to a ComboBox using the combo's DataSource property, the combo box fills up with items from the array list....
0
4807
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 manually inserted a row in the table bound to the Combo box. The InsertAt Method of adding a row just does not work. Hope this helps anyone with this problem. john
13
2414
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 have a Form with textBox1, textBox2, btnShowValue, and btnNew. Let's also suppose I have this code. //member of Form
7
4457
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
3183
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 I would like to show a checkboxlist within my formview to represent them. I just have no idea how to bind this collection to a list within the formview? Has anyone got any ideas on this? I don't need the full code, just a pointer in the right...
9
2805
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 datasource that contains the code. Now suppose that you want it to be read-only? That is, you have the 'code' in your DB, want the associated 'description' to display, but not let the user change it on this particular form. There is no read-only...
5
3948
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' together with a search form, and the user can go back and forth. When the user hits ok, the form is hidden and the search form is shown and visa-versa. The problem is that when the form is hidden when the labels visible property is False, and then...
3
3206
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 SelectedValue property is bound to one of our business objects. When the control is validated the business object's property is updated. (DataSourceUpdateMode = OnValidate)
0
9670
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.