how to implement IBindingList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

There is an sample class CustomerList to implement the interface IBindingList
in MSDN.

But it dosen't have codes for followings to show how to sort the collection.

Can you provide codes to to it?

Thanks
Keith

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

void IBindingList.AddIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection
direction)
{
throw new NotSupportedException();
}

int IBindingList.Find(PropertyDescriptor property, object key)
{
throw new NotSupportedException();
}

void IBindingList.RemoveIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.RemoveSort()
{
throw new NotSupportedException();
}.
 
keith,

It shouldn't be that hard. Basically, you would have to reorder the
list internally, and then fire the ListChanged event, passing
ListChangedType.Reset, to indicate that much of the list has changed.

Hope this helps.
 
But problem is no sample codes. Just don't know how to start coding for
something like

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

Nicholas Paldino said:
keith,

It shouldn't be that hard. Basically, you would have to reorder the
list internally, and then fire the ListChanged event, passing
ListChangedType.Reset, to indicate that much of the list has changed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

keith said:
There is an sample class CustomerList to implement the interface
IBindingList
in MSDN.

But it dosen't have codes for followings to show how to sort the
collection.

Can you provide codes to to it?

Thanks
Keith

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

void IBindingList.AddIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.ApplySort(PropertyDescriptor property, ListSortDirection
direction)
{
throw new NotSupportedException();
}

int IBindingList.Find(PropertyDescriptor property, object key)
{
throw new NotSupportedException();
}

void IBindingList.RemoveIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.RemoveSort()
{
throw new NotSupportedException();
}.
 
Keith,

That's dependent on how you store the list. Basically, the list has an
indexer on it. Based on how you store the elements internally, you have to
change it so that when an index of zero is passed to the indexer, you return
the first item in the list sorted on the properties passed through in the
sort. If one was passed, then you return the next item, and so on, and so
on.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

keith said:
But problem is no sample codes. Just don't know how to start coding for
something like

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

Nicholas Paldino said:
keith,

It shouldn't be that hard. Basically, you would have to reorder the
list internally, and then fire the ListChanged event, passing
ListChangedType.Reset, to indicate that much of the list has changed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

keith said:
There is an sample class CustomerList to implement the interface
IBindingList
in MSDN.

But it dosen't have codes for followings to show how to sort the
collection.

Can you provide codes to to it?

Thanks
Keith

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

void IBindingList.AddIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.ApplySort(PropertyDescriptor property,
ListSortDirection
direction)
{
throw new NotSupportedException();
}

int IBindingList.Find(PropertyDescriptor property, object key)
{
throw new NotSupportedException();
}

void IBindingList.RemoveIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.RemoveSort()
{
throw new NotSupportedException();
}.
 
I know it is not too hard. But there is no any sample for these parts in MSDN.

It is not easy to code something you don't what should look like?

Nicholas Paldino said:
Keith,

That's dependent on how you store the list. Basically, the list has an
indexer on it. Based on how you store the elements internally, you have to
change it so that when an index of zero is passed to the indexer, you return
the first item in the list sorted on the properties passed through in the
sort. If one was passed, then you return the next item, and so on, and so
on.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

keith said:
But problem is no sample codes. Just don't know how to start coding for
something like

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

Nicholas Paldino said:
keith,

It shouldn't be that hard. Basically, you would have to reorder the
list internally, and then fire the ListChanged event, passing
ListChangedType.Reset, to indicate that much of the list has changed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

There is an sample class CustomerList to implement the interface
IBindingList
in MSDN.

But it dosen't have codes for followings to show how to sort the
collection.

Can you provide codes to to it?

Thanks
Keith

PropertyDescriptor IBindingList.SortProperty
{
get { throw new NotSupportedException(); }
}

void IBindingList.AddIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.ApplySort(PropertyDescriptor property,
ListSortDirection
direction)
{
throw new NotSupportedException();
}

int IBindingList.Find(PropertyDescriptor property, object key)
{
throw new NotSupportedException();
}

void IBindingList.RemoveIndex(PropertyDescriptor property)
{
throw new NotSupportedException();
}

void IBindingList.RemoveSort()
{
throw new NotSupportedException();
}.
 
Back
Top