By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

DataGridView - BindingSource (Object) and ComboBox cell

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.