473,399 Members | 2,478 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,399 software developers and data experts.

databindings

hi i have the following code in my project

ArrayList pictures = (new Pictures()).GetAllPictures();
allPictures.DataSource = pictures;
allPictures.DisplayMember = "pictures.ToString()"; //pictures.ToString
returns the names of the pictures.
allPictures.ValueMember = "pictures.Bitmap"; //this returns the
actual picture. and i get the foll error here

private void allPictures_SelectedValueChanged(object sender,
System.EventArgs e)
{
if (allPictures.SelectedIndex != -1)
pictureBox.Image = (Image)allPictures.SelectedValue; //this is used to
display the image in the picture box
}

System.ArgumentException: Cannot create a child list for field pictures.
at System.Windows.Forms.BindingContext.EnsureListMana ger(Object
dataSource, String dataMember)
at System.Windows.Forms.BindingContext.get_Item(Objec t dataSource, String
dataMember)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring value)
at TreeViewImages.Form1.Form1_Load(Object sender, EventArgs e) in
form1.cs:line 314
what am i doing wrong.
Nov 16 '05 #1
3 3982
Hi,

First of all, try to remove the "pictures." prefix from the DisplayMember
and the ValueMember initialization values. To the best of my knowledge, the
prefix is not necessary in your databinding scenario.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"frazer" <ic***@hotmail.com> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
hi i have the following code in my project

ArrayList pictures = (new Pictures()).GetAllPictures();
allPictures.DataSource = pictures;
allPictures.DisplayMember = "pictures.ToString()"; //pictures.ToString
returns the names of the pictures.
allPictures.ValueMember = "pictures.Bitmap"; //this returns the
actual picture. and i get the foll error here

private void allPictures_SelectedValueChanged(object sender,
System.EventArgs e)
{
if (allPictures.SelectedIndex != -1)
pictureBox.Image = (Image)allPictures.SelectedValue; //this is used to display the image in the picture box
}

System.ArgumentException: Cannot create a child list for field pictures.
at System.Windows.Forms.BindingContext.EnsureListMana ger(Object
dataSource, String dataMember)
at System.Windows.Forms.BindingContext.get_Item(Objec t dataSource, String dataMember)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring value)
at TreeViewImages.Form1.Form1_Load(Object sender, EventArgs e) in
form1.cs:line 314
what am i doing wrong.


Nov 16 '05 #2
"frazer" <ic***@hotmail.com> wrote in
news:OE**************@TK2MSFTNGP09.phx.gbl:
hi i have the following code in my project

ArrayList pictures = (new Pictures()).GetAllPictures();
allPictures.DataSource = pictures;
allPictures.DisplayMember = "pictures.ToString()"; //pictures.ToString
returns the names of the pictures.
You can't bind to a method, only to properties. You bind the
datasource pictures. In that datasource, objects are stored. for
DisplayMember you specify which property of THESE OBJECTS the control has
to bind to. If you picture object doesn't have a property 'Name', add it
and bind to that. Below, bind to Bitmap, not pictures.Bitmap.

FB
allPictures.ValueMember = "pictures.Bitmap"; //this returns the
actual picture. and i get the foll error here

private void allPictures_SelectedValueChanged(object sender,
System.EventArgs e)
{
if (allPictures.SelectedIndex != -1)
pictureBox.Image = (Image)allPictures.SelectedValue; //this is used
to
display the image in the picture box
}

System.ArgumentException: Cannot create a child list for field pictures.
at System.Windows.Forms.BindingContext.EnsureListMana ger(Object
dataSource, String dataMember)
at System.Windows.Forms.BindingContext.get_Item(Objec t dataSource,
String
dataMember)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring value)
at TreeViewImages.Form1.Form1_Load(Object sender, EventArgs e) in
form1.cs:line 314
what am i doing wrong.


--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #3
hi
that works fine.
now i want to display an image when the user clicks on combo box items.
i can do that but i have to cast it.

Picture p = (Picture)allPictures.SelectedItem;
this.pictureBox.Image = (Bitmap)(p.Bitmap);

this doesnt work.
this.pictureBox.Image = (Bitmap)allPictures.SelectedItem ;

shouldnt it cast it to a picture object automatically?
rather than me explicitly casting it?

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:Xn********************************@207.46.248 .16...
"frazer" <ic***@hotmail.com> wrote in
news:OE**************@TK2MSFTNGP09.phx.gbl:
hi i have the following code in my project

ArrayList pictures = (new Pictures()).GetAllPictures();
allPictures.DataSource = pictures;
allPictures.DisplayMember = "pictures.ToString()"; //pictures.ToString
returns the names of the pictures.


You can't bind to a method, only to properties. You bind the
datasource pictures. In that datasource, objects are stored. for
DisplayMember you specify which property of THESE OBJECTS the control has
to bind to. If you picture object doesn't have a property 'Name', add it
and bind to that. Below, bind to Bitmap, not pictures.Bitmap.

FB
allPictures.ValueMember = "pictures.Bitmap"; //this returns the
actual picture. and i get the foll error here

private void allPictures_SelectedValueChanged(object sender,
System.EventArgs e)
{
if (allPictures.SelectedIndex != -1)
pictureBox.Image = (Image)allPictures.SelectedValue; //this is used
to
display the image in the picture box
}

System.ArgumentException: Cannot create a child list for field pictures.
at System.Windows.Forms.BindingContext.EnsureListMana ger(Object
dataSource, String dataMember)
at System.Windows.Forms.BindingContext.get_Item(Objec t dataSource,
String
dataMember)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring value)
at TreeViewImages.Form1.Form1_Load(Object sender, EventArgs e) in
form1.cs:line 314
what am i doing wrong.


--
Get LLBLGen Pro, the new O/R mapper for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Nov 16 '05 #4

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

Similar topics

9
by: HAN(removethis)twister | last post by:
I've tried to create 11 textboxes as variables (not actually visible in the program, not in Windows Form Designer) and have set DataBindings to the text properties of the TextBoxes BUT according to...
2
by: C Glenn | last post by:
This is admitedly vague. But so is my understanding of the problem. I'm using this chunk of code: retControl.DataBindings.Add(ctrlBinding.PropertyName,DataSource,BindingField); This resolves...
0
by: XenReborn | last post by:
Ok this should be simple. I made a form, added a combobox (for selecting items to edit, not for updating fields), several textboxes, a few checkboxes etc. On formshow it connects to my database,...
2
by: marcf | last post by:
Hi everyone, I've just studio using VS2008 and have a quick question regarding databindings, i'm fairly handy with vb6 so this question really relates to good practice rather than actual coding. ...
1
by: janj | last post by:
Hi all, I'm having a problem binding two object properties to properties of another object. The code below works as expected when only one binding is added but doesn't work at all (still compiles)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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...
0
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,...

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.