Here is an example of a SortedList that works as a datasource to the ComboBox
and a generic SortedList<that does not works as a datasource to the
ComboBox.
Why? If I use List and generic List<>, both works.
private void Form1_Load(object sender, EventArgs e)
{
System.Collections.SortedList QA1 = new
System.Collections.SortedList();
QA1["Name1"] = new Query("Name1", "Group1", true);
QA1["Name2"] = new Query("Name2", "Group1", true);
comboBox1.DataSource = QA1.Values; // Works !
System.Collections.Generic.SortedList<string, QueryQA2 = new
System.Collections.Generic.SortedList<string, Query>();
QA2["Name1"] = new Query("Name1", "Group1", true);
QA2["Name2"] = new Query("Name2", "Group1", true);
comboBox1.DataSource = QA2.Values; // Does not works
}
Here's the QUERY.cls code in case you're wondering:
sing System;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Query.
/// </summary>
public class Query : IComparable
{
string m_name ;
string m_group;
string m_email;
bool m_IsDirect;
public Query(string Name , string Group, bool IsDirect )
{
m_name = Name;
m_group = Group;
m_IsDirect = IsDirect;
m_email = "";
}
public Query(string Name , string Group, bool IsDirect, string Email)
{
m_name = Name;
m_group = Group;
m_email = Email;
m_IsDirect = IsDirect;
}
public string Email
{
get
{
return m_email;
}
set
{
m_email = value;
}
}
public bool IsDirect
{
get
{
return m_IsDirect;
}
set
{
m_IsDirect = value;
}
}
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
}
}
public string Group
{
get
{
return m_group;
}
set
{
m_group = value;
}
}
public string Display
{
get
{
return string.Format("{0}{1}\t{2}",m_IsDirect ? " \t" : "\x2206\t",
m_group, m_name);
}
}
public string DisplayALL
{
get
{
return string.Format("{0}\t{1}\t{2}",m_group, m_name, m_email);
}
}
#region IComparable Members
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
// int IComparer.Compare( Object one, Object two ) {
// return( (new CaseInsensitiveComparer()).Compare( y, x ) );
// }
public int CompareTo(object obj)
{
if(obj is Query)
{
Query item = (Query) obj;
return m_name.CompareTo(item.m_name);
}
throw new ArgumentException("This object is not a Query Class");
}
#endregion
}
} 4 10096
by the way, the error is
"Complex DataBinding accepts as a data source either an IList or an
IListSource."
"SHEBERT" wrote:
Here is an example of a SortedList that works as a datasource to the ComboBox
and a generic SortedList<that does not works as a datasource to the
ComboBox.
Why? If I use List and generic List<>, both works.
private void Form1_Load(object sender, EventArgs e)
{
System.Collections.SortedList QA1 = new
System.Collections.SortedList();
QA1["Name1"] = new Query("Name1", "Group1", true);
QA1["Name2"] = new Query("Name2", "Group1", true);
comboBox1.DataSource = QA1.Values; // Works !
System.Collections.Generic.SortedList<string, QueryQA2 = new
System.Collections.Generic.SortedList<string, Query>();
QA2["Name1"] = new Query("Name1", "Group1", true);
QA2["Name2"] = new Query("Name2", "Group1", true);
comboBox1.DataSource = QA2.Values; // Does not works
}
Here's the QUERY.cls code in case you're wondering:
sing System;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Query.
/// </summary>
public class Query : IComparable
{
string m_name ;
string m_group;
string m_email;
bool m_IsDirect;
public Query(string Name , string Group, bool IsDirect )
{
m_name = Name;
m_group = Group;
m_IsDirect = IsDirect;
m_email = "";
}
public Query(string Name , string Group, bool IsDirect, string Email)
{
m_name = Name;
m_group = Group;
m_email = Email;
m_IsDirect = IsDirect;
}
public string Email
{
get
{
return m_email;
}
set
{
m_email = value;
}
}
public bool IsDirect
{
get
{
return m_IsDirect;
}
set
{
m_IsDirect = value;
}
}
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
}
}
public string Group
{
get
{
return m_group;
}
set
{
m_group = value;
}
}
public string Display
{
get
{
return string.Format("{0}{1}\t{2}",m_IsDirect ? " \t" : "\x2206\t",
m_group, m_name);
}
}
public string DisplayALL
{
get
{
return string.Format("{0}\t{1}\t{2}",m_group, m_name, m_email);
}
}
#region IComparable Members
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
// int IComparer.Compare( Object one, Object two ) {
// return( (new CaseInsensitiveComparer()).Compare( y, x ) );
// }
public int CompareTo(object obj)
{
if(obj is Query)
{
Query item = (Query) obj;
return m_name.CompareTo(item.m_name);
}
throw new ArgumentException("This object is not a Query Class");
}
#endregion
}
}
SHEBERT,
It's exactly what the error says. The DataSource needs to implement
IList or IListSource. The SortedList<TKey, TValueclass does not implement
IList or IListSource interface, so it can't be used for the DataSource
property on the ComboBox.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"SHEBERT" <SH*****@discussions.microsoft.comwrote in message
news:91**********************************@microsof t.com...
by the way, the error is
"Complex DataBinding accepts as a data source either an IList or an
IListSource."
"SHEBERT" wrote:
>Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox.
Why? If I use List and generic List<>, both works.
private void Form1_Load(object sender, EventArgs e) { System.Collections.SortedList QA1 = new System.Collections.SortedList(); QA1["Name1"] = new Query("Name1", "Group1", true); QA1["Name2"] = new Query("Name2", "Group1", true); comboBox1.DataSource = QA1.Values; // Works !
System.Collections.Generic.SortedList<string, QueryQA2 = new System.Collections.Generic.SortedList<string, Query>(); QA2["Name1"] = new Query("Name1", "Group1", true); QA2["Name2"] = new Query("Name2", "Group1", true); comboBox1.DataSource = QA2.Values; // Does not works } Here's the QUERY.cls code in case you're wondering:
sing System;
namespace WindowsApplication1 { /// <summary> /// Summary description for Query. /// </summary> public class Query : IComparable { string m_name ; string m_group; string m_email; bool m_IsDirect;
public Query(string Name , string Group, bool IsDirect ) { m_name = Name; m_group = Group; m_IsDirect = IsDirect; m_email = ""; }
public Query(string Name , string Group, bool IsDirect, string Email) { m_name = Name; m_group = Group; m_email = Email; m_IsDirect = IsDirect; }
public string Email { get { return m_email; } set { m_email = value; } }
public bool IsDirect { get { return m_IsDirect; } set { m_IsDirect = value; } }
public string Name { get { return m_name; } set { m_name = value; } }
public string Group { get { return m_group; } set { m_group = value; } }
public string Display { get { return string.Format("{0}{1}\t{2}",m_IsDirect ? " \t" : "\x2206\t", m_group, m_name); } } public string DisplayALL { get { return string.Format("{0}\t{1}\t{2}",m_group, m_name, m_email); } }
#region IComparable Members // Calls CaseInsensitiveComparer.Compare with the parameters reversed. // int IComparer.Compare( Object one, Object two ) { // return( (new CaseInsensitiveComparer()).Compare( y, x ) ); // }
public int CompareTo(object obj) { if(obj is Query) { Query item = (Query) obj; return m_name.CompareTo(item.m_name); } throw new ArgumentException("This object is not a Query Class"); }
#endregion } }
The LIST object works, either LIST or generics LIST<works ! Even if LIST<>
is generics it does work as a COMBOXBOX datasource.
then why SortedList implements ILIST (since it's working as a COMBOBOX
DataSource) and not generics SortedList <>?
what's the difference between SORTEDLIST and Generics SORTEDLIST<that it
won't works?
"Nicholas Paldino [.NET/C# MVP]" wrote:
SHEBERT,
It's exactly what the error says. The DataSource needs to implement
IList or IListSource. The SortedList<TKey, TValueclass does not implement
IList or IListSource interface, so it can't be used for the DataSource
property on the ComboBox.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"SHEBERT" <SH*****@discussions.microsoft.comwrote in message
news:91**********************************@microsof t.com...
by the way, the error is
"Complex DataBinding accepts as a data source either an IList or an
IListSource."
"SHEBERT" wrote:
Here is an example of a SortedList that works as a datasource to the
ComboBox
and a generic SortedList<that does not works as a datasource to the
ComboBox.
Why? If I use List and generic List<>, both works.
private void Form1_Load(object sender, EventArgs e)
{
System.Collections.SortedList QA1 = new
System.Collections.SortedList();
QA1["Name1"] = new Query("Name1", "Group1", true);
QA1["Name2"] = new Query("Name2", "Group1", true);
comboBox1.DataSource = QA1.Values; // Works !
System.Collections.Generic.SortedList<string, QueryQA2 =
new
System.Collections.Generic.SortedList<string, Query>();
QA2["Name1"] = new Query("Name1", "Group1", true);
QA2["Name2"] = new Query("Name2", "Group1", true);
comboBox1.DataSource = QA2.Values; // Does not works
}
Here's the QUERY.cls code in case you're wondering:
sing System;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Query.
/// </summary>
public class Query : IComparable
{
string m_name ;
string m_group;
string m_email;
bool m_IsDirect;
public Query(string Name , string Group, bool IsDirect )
{
m_name = Name;
m_group = Group;
m_IsDirect = IsDirect;
m_email = "";
}
public Query(string Name , string Group, bool IsDirect, string Email)
{
m_name = Name;
m_group = Group;
m_email = Email;
m_IsDirect = IsDirect;
}
public string Email
{
get
{
return m_email;
}
set
{
m_email = value;
}
}
public bool IsDirect
{
get
{
return m_IsDirect;
}
set
{
m_IsDirect = value;
}
}
public string Name
{
get
{
return m_name;
}
set
{
m_name = value;
}
}
public string Group
{
get
{
return m_group;
}
set
{
m_group = value;
}
}
public string Display
{
get
{
return string.Format("{0}{1}\t{2}",m_IsDirect ? " \t" : "\x2206\t",
m_group, m_name);
}
}
public string DisplayALL
{
get
{
return string.Format("{0}\t{1}\t{2}",m_group, m_name, m_email);
}
}
#region IComparable Members
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
// int IComparer.Compare( Object one, Object two ) {
// return( (new CaseInsensitiveComparer()).Compare( y, x ) );
// }
public int CompareTo(object obj)
{
if(obj is Query)
{
Query item = (Query) obj;
return m_name.CompareTo(item.m_name);
}
throw new ArgumentException("This object is not a Query Class");
}
#endregion
}
}
You're binding to the object returned from the Values property, so let's
examine what you really get using reflector
The System.Collections.SortedList.Values property is typed as returning
ICollection, so in theory you should not be able to bind to this. However,
what it really returns is an instance of the private type
System.Collections.SortedList.Values. This class implements both IList and
ICollection, so binding works anyway (but this might very well change in the
future)
The System.Collections.Generic.SortedList(TKey, TValue).Values is typed as
returning IList<TValue>, so you should not be able to bind to this. But in
reality (just as for SortedList.Values above) it returns an instance of the
private type System.Collections.Generic.SortedList(TKey,
TValue).ValueList<TKey, TValue. Problem is this list doesn't implement IList
so it cannot be used for databinding
The generic List implements IList so it's perfectly valid as a binding
source
/claes
"SHEBERT" <SH*****@discussions.microsoft.comwrote in message
news:9E**********************************@microsof t.com...
The LIST object works, either LIST or generics LIST<works ! Even if
LIST<>
is generics it does work as a COMBOXBOX datasource.
then why SortedList implements ILIST (since it's working as a COMBOBOX
DataSource) and not generics SortedList <>?
what's the difference between SORTEDLIST and Generics SORTEDLIST<that it
won't works?
"Nicholas Paldino [.NET/C# MVP]" wrote:
>SHEBERT,
It's exactly what the error says. The DataSource needs to implement IList or IListSource. The SortedList<TKey, TValueclass does not implement IList or IListSource interface, so it can't be used for the DataSource property on the ComboBox.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"SHEBERT" <SH*****@discussions.microsoft.comwrote in message news:91**********************************@microso ft.com...
by the way, the error is
"Complex DataBinding accepts as a data source either an IList or an
IListSource."
"SHEBERT" wrote:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox.
Why? If I use List and generic List<>, both works.
private void Form1_Load(object sender, EventArgs e) { System.Collections.SortedList QA1 = new System.Collections.SortedList(); QA1["Name1"] = new Query("Name1", "Group1", true); QA1["Name2"] = new Query("Name2", "Group1", true); comboBox1.DataSource = QA1.Values; // Works !
System.Collections.Generic.SortedList<string, QueryQA2 = new System.Collections.Generic.SortedList<string, Query>(); QA2["Name1"] = new Query("Name1", "Group1", true); QA2["Name2"] = new Query("Name2", "Group1", true); comboBox1.DataSource = QA2.Values; // Does not works } Here's the QUERY.cls code in case you're wondering:
sing System;
namespace WindowsApplication1 { /// <summary> /// Summary description for Query. /// </summary> public class Query : IComparable { string m_name ; string m_group; string m_email; bool m_IsDirect;
public Query(string Name , string Group, bool IsDirect ) { m_name = Name; m_group = Group; m_IsDirect = IsDirect; m_email = ""; }
public Query(string Name , string Group, bool IsDirect, string Email) { m_name = Name; m_group = Group; m_email = Email; m_IsDirect = IsDirect; }
public string Email { get { return m_email; } set { m_email = value; } }
public bool IsDirect { get { return m_IsDirect; } set { m_IsDirect = value; } }
public string Name { get { return m_name; } set { m_name = value; } }
public string Group { get { return m_group; } set { m_group = value; } }
public string Display { get { return string.Format("{0}{1}\t{2}",m_IsDirect ? " \t" : "\x2206\t", m_group, m_name); } } public string DisplayALL { get { return string.Format("{0}\t{1}\t{2}",m_group, m_name, m_email); } }
#region IComparable Members // Calls CaseInsensitiveComparer.Compare with the parameters reversed. // int IComparer.Compare( Object one, Object two ) { // return( (new CaseInsensitiveComparer()).Compare( y, x ) ); // }
public int CompareTo(object obj) { if(obj is Query) { Query item = (Query) obj; return m_name.CompareTo(item.m_name); } throw new ArgumentException("This object is not a Query Class"); }
#endregion } }
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: gerrod |
last post by:
Hi -
Does anyone know a way to created a SortedList (in the
System.Collections namespace) that will sort on VALUES instead of
KEYS... ?
The scenario is this - I have a SortedList containing...
|
by: nevin |
last post by:
Hello all,
I've looked on the net and can't seem to find what I need so I must be
searching badly or have (another) 'non-problem'.
I am simply trying to move the values of a hastable or sorted...
|
by: Ori :) |
last post by:
Hi Guys,
I have a sortedlist which holds a group of "CartItem" items. following is
the CartItem class:
Public Class CartItem
Public ProdID As Integer
Public Name As String
Public Price As...
|
by: greg.merideth |
last post by:
Is it possible to serialize SortedList<T,V> or do I need to come up
with my own method to get the data into and out the list? I'm pretty
sure I know that it's "no" I'm just curious if there are...
|
by: Sean |
last post by:
How does one bind a SortedList to anything. If it cant be done why would
anyone ever even use a sortedlist?
We are currently (via business objects that use interfaces etc) binding
gridviews to...
|
by: Prez |
last post by:
I started writing .net code yesterday and I am grasping it well enough.
I have a few questions about SortedLists.
I am using managed C++ if that makes any difference.
Of the examples I...
|
by: raylopez99 |
last post by:
I seem to get name collision between the Generic collection SortedList
and C++.NET Framework collection SortedList.
How to resolve? Here are the libraries that seem to clash:...
|
by: Lonifasiko |
last post by:
Hi,
I'm having quite a strange behaviour when using Generics classes and
ComboBox controls in Winforms applications. Hope somebody has seen the
same behaviour.
Two combobox controls in my...
|
by: n3tx |
last post by:
Hi!
I have a problem with sortedlist, i guess i dont understand how it works.
I have a method called GetPublishingPlaces that returns an IList<PublishingPlace> (ex. contains 11 rows)
I want...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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: 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,...
| |