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

Home Posts Topics Members FAQ

IList items "keeping position"

Hello All,

I have a class implementing IList and a global object of this class type.
I have two different form objects. One has a ListBox and the other has
ComboBox. Both of their datasources are set to this global object.
The problem is that when I select an item in the ListBox the combobox
selecteditem changes to the same item selected in the ListBox. And the
oposite is also true, so when I select an item in the ComboBox my ListBox
SelectedItem changes.
I have no idea why this is happening. How can I prevent this from happening?

Thanks in advance for all the replies,

Giovanni Bassi
Nov 20 '05 #1
3 4519
Giovanni,
Oh! the joys of databinding. :-)

When you bind the first ListBox to the list, an entry is made in the forms
BindingContext property, when you bind the ComboBox to the same list, the
form sees the entry in the BindingContext and reuses it.

The easiest way to fix this is to have two lists.

Without physically cloning the list an easy way to have two lists is to
introduce a 'View' class. A 'View' class is a class that implements IList or
IBindingList that holds a reference to your original IList, delegating all
the IList methods to this contained list. Similar to the relationship
between DataTable & DataView, a DataTable can have multiple independent
DataView objects referring to it. When you bind to a DataTable you are
actually binding to a DataView object. By implementing IBindingList and
other advanced data binding interfaces, you can give simple collection such
as ArrayList rich data binding abilities...

Something like:

Public Class ListView
Implements IList

Private ReadOnly m_list As IList

Public Sub New(ByVal list As IList)
m_list = list
End Sub

Public Sub CopyTo(ByVal array As Array, ByVal index As Integer) _
Implements ICollection.Cop yTo
m_list.CopyTo(a rray, index)
End Sub

Public ReadOnly Property Count() As Integer _
Implements ICollection.Cou nt
Get
Return m_list.Count
End Get
End Property

...
' all other IList methods delegate to m_list as above

End Class

Then you would bind to ListView objects:

Public Class MainForm

Private Sub MainForm_Load

Dim list As New ArrayList

Me.ListBox1.Dat aSource = New ListView(list)
Me.ComboBox1.Da taSource = New ListView(list)

End Sub
Hope this helps
Jay

"Giovanni Bassi" <gb****@coair.c om> wrote in message
news:eW******** ******@TK2MSFTN GP11.phx.gbl...
Hello All,

I have a class implementing IList and a global object of this class type.
I have two different form objects. One has a ListBox and the other has
ComboBox. Both of their datasources are set to this global object.
The problem is that when I select an item in the ListBox the combobox
selecteditem changes to the same item selected in the ListBox. And the
oposite is also true, so when I select an item in the ComboBox my ListBox
SelectedItem changes.
I have no idea why this is happening. How can I prevent this from happening?
Thanks in advance for all the replies,

Giovanni Bassi

Nov 20 '05 #2
Hello Jay,

Thanks for giving me some light on this subject. I really appreciate your
help.
Regarding your demonstration on how to extend the ArrayList, I had already
done that. Still the problem would occur. Your explanation helped very much,
though, because you reminded me of the BindingContext, which was totally
forgot by me...
I have simply added two simple lines where I create a BindingContext object
and another one where I set the ComboBox's BindingContext Property to this
new object and no more problems. The objects are now independent.

Thanks again!

Giovanni Bassi
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:uH******** ******@TK2MSFTN GP10.phx.gbl...
Giovanni,
Oh! the joys of databinding. :-)

When you bind the first ListBox to the list, an entry is made in the forms
BindingContext property, when you bind the ComboBox to the same list, the
form sees the entry in the BindingContext and reuses it.

The easiest way to fix this is to have two lists.

Without physically cloning the list an easy way to have two lists is to
introduce a 'View' class. A 'View' class is a class that implements IList or IBindingList that holds a reference to your original IList, delegating all
the IList methods to this contained list. Similar to the relationship
between DataTable & DataView, a DataTable can have multiple independent
DataView objects referring to it. When you bind to a DataTable you are
actually binding to a DataView object. By implementing IBindingList and
other advanced data binding interfaces, you can give simple collection such as ArrayList rich data binding abilities...

Something like:

Public Class ListView
Implements IList

Private ReadOnly m_list As IList

Public Sub New(ByVal list As IList)
m_list = list
End Sub

Public Sub CopyTo(ByVal array As Array, ByVal index As Integer) _
Implements ICollection.Cop yTo
m_list.CopyTo(a rray, index)
End Sub

Public ReadOnly Property Count() As Integer _
Implements ICollection.Cou nt
Get
Return m_list.Count
End Get
End Property

...
' all other IList methods delegate to m_list as above

End Class

Then you would bind to ListView objects:

Public Class MainForm

Private Sub MainForm_Load

Dim list As New ArrayList

Me.ListBox1.Dat aSource = New ListView(list)
Me.ComboBox1.Da taSource = New ListView(list)

End Sub
Hope this helps
Jay

"Giovanni Bassi" <gb****@coair.c om> wrote in message
news:eW******** ******@TK2MSFTN GP11.phx.gbl...
Hello All,

I have a class implementing IList and a global object of this class type. I have two different form objects. One has a ListBox and the other has
ComboBox. Both of their datasources are set to this global object.
The problem is that when I select an item in the ListBox the combobox
selecteditem changes to the same item selected in the ListBox. And the
oposite is also true, so when I select an item in the ComboBox my ListBox SelectedItem changes.
I have no idea why this is happening. How can I prevent this from

happening?

Thanks in advance for all the replies,

Giovanni Bassi


Nov 20 '05 #3
Giovanni,
In case you did not try it. My sample of just setting the DataSource to
distinct ListView objects:
Me.ListBox1.Dat aSource = New ListView(list)
Me.ComboBox1.Da taSource = New ListView(list)
Keeps the two data sources separate without getting into the specifics of a
BindingContext hidden, while allowing them to share a common actual
ArrayList.

Hope this helps
Jay

"Giovanni Bassi" <gb****@coair.c om> wrote in message
news:uJ******** ******@tk2msftn gp13.phx.gbl...
Hello Jay,

Thanks for giving me some light on this subject. I really appreciate your
help.
Regarding your demonstration on how to extend the ArrayList, I had already
done that. Still the problem would occur. Your explanation helped very much, though, because you reminded me of the BindingContext, which was totally
forgot by me...
I have simply added two simple lines where I create a BindingContext object and another one where I set the ComboBox's BindingContext Property to this
new object and no more problems. The objects are now independent.

Thanks again!

Giovanni Bassi
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message news:uH******** ******@TK2MSFTN GP10.phx.gbl...
Giovanni,
Oh! the joys of databinding. :-)

When you bind the first ListBox to the list, an entry is made in the forms BindingContext property, when you bind the ComboBox to the same list, the form sees the entry in the BindingContext and reuses it.

The easiest way to fix this is to have two lists.

Without physically cloning the list an easy way to have two lists is to
introduce a 'View' class. A 'View' class is a class that implements IList
or
IBindingList that holds a reference to your original IList, delegating

all the IList methods to this contained list. Similar to the relationship
between DataTable & DataView, a DataTable can have multiple independent
DataView objects referring to it. When you bind to a DataTable you are
actually binding to a DataView object. By implementing IBindingList and
other advanced data binding interfaces, you can give simple collection

such
as ArrayList rich data binding abilities...

Something like:

Public Class ListView
Implements IList

Private ReadOnly m_list As IList

Public Sub New(ByVal list As IList)
m_list = list
End Sub

Public Sub CopyTo(ByVal array As Array, ByVal index As Integer) _ Implements ICollection.Cop yTo
m_list.CopyTo(a rray, index)
End Sub

Public ReadOnly Property Count() As Integer _
Implements ICollection.Cou nt
Get
Return m_list.Count
End Get
End Property

...
' all other IList methods delegate to m_list as above

End Class

Then you would bind to ListView objects:

Public Class MainForm

Private Sub MainForm_Load

Dim list As New ArrayList

Me.ListBox1.Dat aSource = New ListView(list)
Me.ComboBox1.Da taSource = New ListView(list)

End Sub
Hope this helps
Jay

"Giovanni Bassi" <gb****@coair.c om> wrote in message
news:eW******** ******@TK2MSFTN GP11.phx.gbl...
Hello All,

I have a class implementing IList and a global object of this class

type. I have two different form objects. One has a ListBox and the other has
ComboBox. Both of their datasources are set to this global object.
The problem is that when I select an item in the ListBox the combobox
selecteditem changes to the same item selected in the ListBox. And the
oposite is also true, so when I select an item in the ComboBox my ListBox SelectedItem changes.
I have no idea why this is happening. How can I prevent this from

happening?

Thanks in advance for all the replies,

Giovanni Bassi



Nov 20 '05 #4

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

Similar topics

2
5162
by: Mark Bordner | last post by:
Hi All, Given the following XML, I've been trying to figure out what XPATH expression will give me the "position" of a <lineitem> within the <shipto> that is its grandparent. To give you an idea of what I'm trying to do...I'm transforming this XML into XSL-FO; which I will process with FOP to produce a PDF file. Each <shipto> element with the XML correlates to a new "section"
1
2609
by: nobody | last post by:
hi there! given <!ELEMENT a (#PCDATA | x)*> <!ELEMENT x (#PCDATA)> how can I find out if x is "embedded" at the beginning <a><x>xxx</x>aaa</a> or at the end <a>aaa<x>xxx</x></a> or in the middle
0
1528
by: Luigi | last post by:
I would know what "criteria" is used in box positioning with the position property. Here my tries (using IE and Opera): I have a box with an absolute positioning (properties used: position, left and top). I noted that if the reference of this box is the "html" box or the "body" box, the browser uses the following rules:
2
1781
by: Jessard | last post by:
Hi All, I am writing a .NET app that accesses an access View. The view has a table column called 'Position'. When i try and right an UpdateCommand string for this using this column I am greeted with a 'Syntax error in Update statement.' when attempting the update. I take that field out and the update works. I am assuming Position is a reserved word. I have even tried changing the name of the column in the View to something other...
4
26590
by: Ghyslaine Crespe | last post by:
Hello, In my script, the line document.getElementById(id).style.background-position = "-200px -500px"; fails ! So, how can I change the background-position value ?
1
1454
by: tschoepi | last post by:
Hi there, if I try to access a table named Position in an Access-Database via OleDbDataAdapter I get an error. If I rename the table to e.g. Positions it works. Any idea how to solve this problem? (There are about 5.000 databases out there at our customers with a table in it named Position!) Thanks a lot for your help
2
5094
by: petermichaux | last post by:
Hi, I tried the following and everything worked fine. element.style.position="relative"; Then I tried to make the CSS rule important and it didn't work. The positioning was all wrong in Safari and very jerky in Firefox. element.style.position="relative !important";
3
3001
by: rsrimantula | last post by:
I have a table with html code <style> div.scroll { height:150px; overflow:auto; } table.scrollable th { position:relative;
1
5105
by: vunet.us | last post by:
Mozilla reported the fix to this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=167801. When input text field is located over div, the cursor cannot be seen unless special CSS properties are applied. The link above illustrates many example. The problem I came across with, is almost identical, except that I need to use position:fixed for my div element instead of position:absolute as in all examples illustrated on Mozilla link. It is...
0
8685
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
9032
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...
1
8905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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...
1
6532
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
4373
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
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
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
2342
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.