473,395 Members | 1,696 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,395 software developers and data experts.

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'
DataGridViewCell 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 14345
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'
DataGridViewCell 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<Tobject 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<Tobject. 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.addr...@phoney.com>
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'
DataGridViewCell 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<Tobject 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<Tobject. 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.addr...@phoney.com>
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'
DataGridViewCell 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<Tobject 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<Tobject. 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
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 INotifyPropertyChanged 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
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...
10
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...
0
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...
1
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...
3
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...
3
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...
7
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...
0
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...
2
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...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.