Hi,
When I bind a BindingList<to a DataGridView and then call RemoveAt(n) on
it, I get ArgumentOutOfRa nge. Could someone explain why?
Sample:
public partial class TestForm2 : Form
{
private BindingList<Per son_personList = new BindingList<Per son>();
public TestForm2()
{
InitializeCompo nent();
}
private void TestForm2_Load( object sender, EventArgs e)
{
Person personA = new Person("Pete");
Person personB = new Person("James") ;
_personList.Add (personA);
_personList.Add (personB);
uxTestGrid.Data Source = _personList;
}
private void uxTestButton_Cl ick(object sender, EventArgs e)
{
_personList.Rem oveAt(0);
}
}
public class Person
{
public string Name = "";
public Person(string name)
{
Name = name;
}
}
So I have two Person objects in the BindingList. Yet, when I call
_personList.Rem oveAt(0) (or 1), I get this exception. If I do not bind it
to the DataGridView, it works fine.
Please help.
Thanks,
Jim 1 2107
Hi Jim,
I'm not exactly sure of this, but I think because Person does not have any
properties it is not visible in the DataGridView, and internally the
DataGridView operates on an empty Person-list. When the datasource removes
one item the DataGridView does not have any items to remove.
If you add a property to Person, it should work fine.
public class Person
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
public Person(string name)
{
Name = name;
}
}
--
Happy Coding!
Morten Wennevik [C# MVP]
"Jim Balo" wrote:
Hi,
When I bind a BindingList<to a DataGridView and then call RemoveAt(n) on
it, I get ArgumentOutOfRa nge. Could someone explain why?
Sample:
public partial class TestForm2 : Form
{
private BindingList<Per son_personList = new BindingList<Per son>();
public TestForm2()
{
InitializeCompo nent();
}
private void TestForm2_Load( object sender, EventArgs e)
{
Person personA = new Person("Pete");
Person personB = new Person("James") ;
_personList.Add (personA);
_personList.Add (personB);
uxTestGrid.Data Source = _personList;
}
private void uxTestButton_Cl ick(object sender, EventArgs e)
{
_personList.Rem oveAt(0);
}
}
public class Person
{
public string Name = "";
public Person(string name)
{
Name = name;
}
}
So I have two Person objects in the BindingList. Yet, when I call
_personList.Rem oveAt(0) (or 1), I get this exception. If I do not bind it
to the DataGridView, it works fine.
Please help.
Thanks,
Jim This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: guy |
last post by:
VB2005
a generic collection that inherits from BindingList, with the code to
support sorting added
(ApplySortCore, SpportsSortingCore etc.)
however when this collection is populated and bound to a DataGridView
ApplySortCore is not called when a grid header is clicked.
how do i ensure this happens?
|
by: Pieter |
last post by:
Hi,
I have a custom List that inherits from BindingList.
It has some methods overloaded, like the Add/Insert/etc to add and remove
some eventhandlers when adding or removing an item T of the list.
The problem happens when:
- I use such a BindingList as DataSource for a BindingSource.
- Add this BindingSource as DataSource for a DataGridView.
- And go to the NewRow and add a new row in the DataGridView.
|
by: Mike Surcouf |
last post by:
Hi All
I have a stored procedure wrapper that returns Collection<T>.
The wrapper is generated by codesmith so I don't really want to start
altering it.
I need to use this collection in a datagridview.
I would like the ability to add to this collection or delete from this
collection using the grid.
I know I will need to use Bindinglist<T> for this but I don't seem to be
able to cast from
|
by: jwilson128 |
last post by:
I am trying to decide whether to use a
system.ComponentModel.BindingList(of T) or a
Sytem.Collections.Generic.List(of T) for a custom collection. In
testing a simple, read-only data binding to a data grid view - they
both work. Are there aspects of databinding that the regular list will
not support and vice-versa, is there any reason to choose a regular
list over the bindinglist? -Jeff
|
by: Rick |
last post by:
VS.net 2005
I'm using a bindinglist(of T) to bind to various controls on a WinForm. I
use the name/value pairs in the "type" for the displayMember and ValueMember
of say a ComboBox control.
For example I might load the TermsNumber and TermsDescription from a
database into the binding list and then use the combobox to feed into a
customer setup form for default terms and for a order setup form for the
individual order terms.
| |
by: Rick |
last post by:
VS 2005
I have a class of BindingList(of T) to use as a datasource for a lookup
combobox. The combobox is to lookup the Terms for a Purchase Order.
When I implement this on my Winform, the combobox does not synch with the
underlying data, i.e. the Terms description does not show for the terms
number.
The combobox does show the Descriptions in the drop-down box, so they are
|
by: =?Utf-8?B?Q2xhdWRl?= |
last post by:
It is possible to capture the "AddingNew" event to create our own object
before it is append to the BindingList (using e.NewObject = new ...)
When the user press delete on a row to remove a row from the DataGridView, I
need to do some stuff before it actualy modify the content of the
BindingList. Is it possible ? I tried to capture "List_Changed" event, but
it's too late, the object is already gone from the bindinglist !
What can I do ?
|
by: jehugaleahsa |
last post by:
Hello:
I am binding a DataGridView with a BindingList<T>, where T is a custom
business object that implements INotifyPropertyChanged.
When you bind a DataGridView to a DataTable, it has this cool little
feature - it will not call DataTable.Rows.Add until after you leave
the DataGridView row. This is cool because it lets your user edit the
record as much as needed to get it into a valid state before actually
adding it to the DataTable.
|
by: myotheraccount |
last post by:
I'm a newbie to c#, so bear with me.
I'm trying to get data into from a DataReader, put it into a
BindingList that is bound into a DataGridView. My code is:
BindingList<stringbl = new BindingList<string>();
BindingSource bs = new BindingSource();
DataGridView dgv = new DataGridView();
load_list()// method that loads the list using the DataReader
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |