473,699 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView - BindingSource (Object) and ComboBox cell

Dear Group,

I'm developing sample window form, using DataGridView control, which
is filled with data through BindingSource, which is based on type of
object, as follow:

public sampleClass
{
public int itemNumber;
public string itemName;
public string itemCategory;
public bool itemActive;

public int ItemNumber
{
get { return itemNumber; }
set { itemNumber = value; }
}
public string ItemName
{
get { return itemName; }
set { itemName = value; }
}
public string ItemCategory
{
get { return itemCategory; }
set { itemCategory = value; }
}
public bool ItemActive
{
get { return itemActive; }
set { itemActive = value; }
}
}

So, everything seems to work perfect, the 'ItemActive'
DataGridViewCel l is checkbox (as required), but the problem is when
I'd like to insert a ComboBox (DropDownList type) into a sample cell.
I have no idea how to do it through the object binding system - in the
matter of fact, is it even possible? Or the only way is through
creating step by step all DataGridView columns?

If any tutorial found, which might help me a bit, don't hesitate
writing it down.

Thank you very much for any help.

All the best,
Przemek M. Zawada

Feb 23 '07 #1
3 14369
On 23 Feb 2007 06:24:23 -0800, "Przemek M. Zawada" <pr************ @gmail.com>
wrote:
>Dear Group,

I'm developing sample window form, using DataGridView control, which
is filled with data through BindingSource, which is based on type of
object, as follow:

public sampleClass
{
public int itemNumber;
public string itemName;
public string itemCategory;
public bool itemActive;

public int ItemNumber
{
get { return itemNumber; }
set { itemNumber = value; }
}
public string ItemName
{
get { return itemName; }
set { itemName = value; }
}
public string ItemCategory
{
get { return itemCategory; }
set { itemCategory = value; }
}
public bool ItemActive
{
get { return itemActive; }
set { itemActive = value; }
}
}

So, everything seems to work perfect, the 'ItemActive'
DataGridViewCe ll is checkbox (as required), but the problem is when
I'd like to insert a ComboBox (DropDownList type) into a sample cell.
I have no idea how to do it through the object binding system - in the
matter of fact, is it even possible? Or the only way is through
creating step by step all DataGridView columns?

If any tutorial found, which might help me a bit, don't hesitate
writing it down.

Thank you very much for any help.

All the best,
Przemek M. Zawada
You will need to create a BindingList<Tob ject containing the objects that
contain at the very least an ID and description for the list you want to bind.
You will then bind the combobox to the list with manually written code. You may
be able to do the binding from the IDE by using a BindingSource object bound to
the BindingList<Tob ject. I've not tried that.

In addition to the above you might want to get the
book "Data Binding with Windows Forms 2.0" by Bryan Noyes. It addresses data
binding with objects extensively.
Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Feb 23 '07 #2
On 23 Lut, 17:49, Otis Mukinfus <phoney.email.a ddr...@phoney.c om>
wrote:
On 23 Feb 2007 06:24:23 -0800, "Przemek M. Zawada" <przemek.zaw... @gmail.com>
wrote:
Dear Group,
I'm developing sample window form, using DataGridView control, which
is filled with data through BindingSource, which is based on type of
object, as follow:
public sampleClass
{
public int itemNumber;
public string itemName;
public string itemCategory;
public bool itemActive;
public int ItemNumber
{
get { return itemNumber; }
set { itemNumber = value; }
}
public string ItemName
{
get { return itemName; }
set { itemName = value; }
}
public string ItemCategory
{
get { return itemCategory; }
set { itemCategory = value; }
}
public bool ItemActive
{
get { return itemActive; }
set { itemActive = value; }
}
}
So, everything seems to work perfect, the 'ItemActive'
DataGridViewCel l is checkbox (as required), but the problem is when
I'd like to insert a ComboBox (DropDownList type) into a sample cell.
I have no idea how to do it through the object binding system - in the
matter of fact, is it even possible? Or the only way is through
creating step by step all DataGridView columns?
If any tutorial found, which might help me a bit, don't hesitate
writing it down.
Thank you very much for any help.
All the best,
Przemek M. Zawada

You will need to create a BindingList<Tob ject containing the objects that
contain at the very least an ID and description for the list you want to bind.
You will then bind the combobox to the list with manually written code. You may
be able to do the binding from the IDE by using a BindingSource object bound to
the BindingList<Tob ject. I've not tried that.

In addition to the above you might want to get the
book "Data Binding with Windows Forms 2.0" by Bryan Noyes. It addresses data
binding with objects extensively.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.comhttp://ww...//www.n5ge.com
Dear Otis,

I probably understood the idea you've explained above, but if it isn't
a big problem, could you paste here simplest example?

What I want to achieve is the following:

Object is defined as MyItemClass and with public fields: ItemID,
ItemName, ItemDescription , ItemCategory. ItemCategory (in
DataGridView) should be a string, which is displayed by (SelectedItem)
in ComboBox, which ones items are loaded from database.

Sample example of initiated object MyItemClass:

ItemID equals 1238
ItemName equals Lorem ipsum
ItemDescription equals Lorem ipsum dolor (...)
ItemCategory {
Category 1
Category 2 [selected]
Category 3
Category 4
}

I presume, that I need to define the type of object which describes
single item category - i.e. (int categoryId, string categoryName), and
then create in my (main) MyItemClass field as an array of for example
ItemCategoryObj[]. What next?

Sorry if that's rookie style of thinking, but I'm trying to upgrade my
knowledge in binding objects into windows forms.

Thank you for fast answer to my problem.

All the best,
Przemek M. Zawada

Feb 23 '07 #3
On 23 Feb 2007 10:31:44 -0800, "Przemek M. Zawada" <pr************ @gmail.com>
wrote:
>On 23 Lut, 17:49, Otis Mukinfus <phoney.email.a ddr...@phoney.c om>
wrote:
>On 23 Feb 2007 06:24:23 -0800, "Przemek M. Zawada" <przemek.zaw... @gmail.com>
wrote:
>Dear Group,
>I'm developing sample window form, using DataGridView control, which
is filled with data through BindingSource, which is based on type of
object, as follow:
>public sampleClass
{
public int itemNumber;
public string itemName;
public string itemCategory;
public bool itemActive;
public int ItemNumber
{
get { return itemNumber; }
set { itemNumber = value; }
}
public string ItemName
{
get { return itemName; }
set { itemName = value; }
}
public string ItemCategory
{
get { return itemCategory; }
set { itemCategory = value; }
}
public bool ItemActive
{
get { return itemActive; }
set { itemActive = value; }
}
}
>So, everything seems to work perfect, the 'ItemActive'
DataGridViewCe ll is checkbox (as required), but the problem is when
I'd like to insert a ComboBox (DropDownList type) into a sample cell.
I have no idea how to do it through the object binding system - in the
matter of fact, is it even possible? Or the only way is through
creating step by step all DataGridView columns?
>If any tutorial found, which might help me a bit, don't hesitate
writing it down.
>Thank you very much for any help.
>All the best,
Przemek M. Zawada

You will need to create a BindingList<Tob ject containing the objects that
contain at the very least an ID and description for the list you want to bind.
You will then bind the combobox to the list with manually written code. You may
be able to do the binding from the IDE by using a BindingSource object bound to
the BindingList<Tob ject. I've not tried that.

In addition to the above you might want to get the
book "Data Binding with Windows Forms 2.0" by Bryan Noyes. It addresses data
binding with objects extensively.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.comhttp://ww...//www.n5ge.com

Dear Otis,

I probably understood the idea you've explained above, but if it isn't
a big problem, could you paste here simplest example?

What I want to achieve is the following:

Object is defined as MyItemClass and with public fields: ItemID,
ItemName, ItemDescription , ItemCategory. ItemCategory (in
DataGridView ) should be a string, which is displayed by (SelectedItem)
in ComboBox, which ones items are loaded from database.

Sample example of initiated object MyItemClass:

ItemID equals 1238
ItemName equals Lorem ipsum
ItemDescriptio n equals Lorem ipsum dolor (...)
ItemCategory {
Category 1
Category 2 [selected]
Category 3
Category 4
}

I presume, that I need to define the type of object which describes
single item category - i.e. (int categoryId, string categoryName), and
then create in my (main) MyItemClass field as an array of for example
ItemCategoryOb j[]. What next?

Sorry if that's rookie style of thinking, but I'm trying to upgrade my
knowledge in binding objects into windows forms.

Thank you for fast answer to my problem.

All the best,
Przemek M. Zawada
Przemek,

You can see some sample code for an object that uses the IEditableObject
interface by going to the Help Index in the VS2k IDE and typing IEditableObject
in the Look for: text box, then click on the about IEditableObject interface
selection.

Do the same searching for INotifyProperty Changed and BindingList(Of T).

The BindingList(Of T) example contains Windows Forms example you might find
useful. Two of the examples I suggest have code in them that creates objects
targeted for data binding, but remember the examples are simple examples to
demonstrate a principle. They are not what I would call industrial strength.

After you have viewed all of these examples you will understand why I did not
send you any sample code.

Using objects as data sources, while giving you the most control over your data
access requires a lot of planning and work, so be ready to do some studying and
experimenting to understand how it works. If you cannot afford to spend the
time studying how it works and if your project is a small one, then you might
want to consider just using the drag and drop methods of creating a data
interface.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Feb 24 '07 #4

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

Similar topics

10
27006
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column for that property 2) Add the column to the datagridview 3) Populate a BindingSource by adding all instances of the above mentioned class. 4) Assign the BindingSource to the datagridview's DataSource property
10
39491
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got some DataGridViewTextBoxCell, DataGridViewComboBoxCell etc, i want to export all that to XML.. Any help is greatly appreciated.
0
1580
by: Pieter Coucke | last post by:
Hi, I have a DataGridView, that contains a list of Articles, which can be added (automaticly via the AllowUserToAddRows) and changed by the user. The current item is also displayed in textboxes under the datagridview, to give more space for the user to change the item. But I'm getting some werid results with it: - When I add the first item to the DataGridView, and I change the values of the cells in the DataGridView, these values are...
1
4162
by: Riley | last post by:
Need some help. I am using datagridview in 2005 with C#. I am calling a web service and filling the datagridview with the data returned. This all works fine. Next step is to take a value from one of the cells in the datagridview and return it back with some other values in an object for another webservice call. The problem is I dont know how to access a cell in a datagridview to do this. Im pretty sure you have to do it thru the binding...
3
56189
by: Freddy Coal | last post by:
Hi, I'm learning to use the Datagridview; I would like sort a column of my DGV, but with code, not with user click over the column, how make that?; Mi other question is how search for a especific chain in my DGV?. Thanks in advance for any help, I'm using VB.Net in VS2005. Freddy Coal
3
6325
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way to get the data in a datagridview to change. For example 2 columns are ID and amount_paid, the datagridview loads on form load with all ID's and amounts. How do I get it to only bring back the selected ID. Sounds like I may need to change the SQL...
7
15653
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
0
1970
by: Hassan | last post by:
Hi, Im using visual studio 2005,C#2 Framework 2.0 In my program, i have a DataGridView where DataGridView.DataSource equal to a BindingSource.DataSource and this BindingSource.DataSource equalt to a DataTable. i handled the event ColumnHeaderMouseClick to perform a sort. i tryied this methods: 1/BindingSource.Sort=mydgvColumn.Name+" ASC ";
2
16841
by: Eric B. | last post by:
I could use a little clarification on using a BindingSource with my DataTable. As I understand it, the BindingSource sits between my data source (a DataTable) and DataGridView and any changes made to it is reflected in the other two? Now if that is so, how should I access the elements of my DataTable? I need to make decisions on what Rows to remove based on comparing the values of the elements. Should I access the individual elements via...
0
8621
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
9041
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
8890
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7757
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...
1
6538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4634
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
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
2355
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.