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

[MC++] DataGrid bound to ArrayList problem

I am having a weird problem with my DataGrid that is bound to an
ArrayList. My situation is as follows:

I have two DataGrids on a modal form. The top grid populates an
ArrayList from a file, then the datagrid is bound to it, and it works
fine. The bottom DataGrid is bound to a different ArrayList that holds
the same type as the first ArrayList. Both DataGrids are set to
Read-Only.

The user selects a row from the top DataGrid, then clicks the "Add"
button to copy it to the bottom DataGrid. If I then click on the entry
in the bottom DataGrid, then click off it, I get the following message
box:

---------------------------
Error when committing the row to the original data store.
---------------------------
Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index Do you want to correct the value?
---------------------------
Yes No
---------------------------

Clicking "Yes" does not help, since the DataGrid is Read-Only so none of
the values can be changed. If I click "No", then I get the exception
text given at the bottom of this post (I removed the reference to my
app's loaded assembly, but I left everything else).
Here is my function where I initialize the DataGrid:

void init_selected_xmtrs_datagrid()
{
using System::Convert;
using System::IO::StreamReader;

selected_xmtrs_list = new ArrayList();

typedef std::vector<Xmtr>::const_iterator XCI;
for (XCI i = selected_xmtrs_->begin(); i != selected_xmtrs_->end(); ++i) {
XmtrWrapper* xw = new XmtrWrapper(*i);
selected_xmtrs_list->Add(xw);
}
/*if (selected_xmtrs_list->Count == 0) {
selected_xmtrs_list->Add(new XmtrWrapper);
datagrid_selected_xmtrs->DataSource = selected_xmtrs_list;
selected_xmtrs_list->Clear();
}*/

datagrid_selected_xmtrs->DataSource = selected_xmtrs_list;

DataGridTableStyle* table_style = XmtrDataGridTableStyle();
datagrid_selected_xmtrs->TableStyles->Clear();
datagrid_selected_xmtrs->TableStyles->Add(table_style);
}

If I uncomment the commented section (which I tried to do to get it to
show the column names when the ArrayList is empty, which didn't work),
then I do not get the error.
Here is my function that gets called when the user clicks the "Add"
button:

System::Void button_add_Click(System::Object * sender, System::EventArgs * e)
{
CurrencyManager* cm = __try_cast<CurrencyManager*>(BindingContext->Item[all_xmtrs_list]);
int num_rows = cm->Count;
for (int i = 0; i < num_rows; ++i) {
if (datagrid_all_xmtrs->IsSelected(i)) {
if (!selected_xmtrs_list->Contains(all_xmtrs_list->Item[i])) {
XmtrWrapper* xw = __try_cast<XmtrWrapper*>(all_xmtrs_list->Item[i]);
Xmtr* xmtr = xw->xmtr;
selected_xmtrs_->push_back(*xmtr);
selected_xmtrs_list->Add(all_xmtrs_list->Item[i]);
selected_xmtrs_list->Sort();
}
}
}
// reset the datasource to refresh the display
datagrid_selected_xmtrs->DataSource = 0;
datagrid_selected_xmtrs->DataSource = selected_xmtrs_list;
}
Can anybody explain what is going on, or how to fix my problem
correctly?
************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.CurrencyManager.CancelCurrent Edit()
at System.Windows.Forms.DataGrid.HandleEndCurrentEdit ()
at System.Windows.Forms.DataGrid.OnLeave_Grid()
at System.Windows.Forms.DataGrid.OnLeave(EventArgs e)
at System.Windows.Forms.Control.NotifyLeave()
at System.Windows.Forms.ContainerControl.UpdateFocuse dControl()
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------

--
Marcus Kwok
Mar 14 '06 #1
0 1217

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

Similar topics

1
by: Stephen | last post by:
I have a really annoying problem with a datagrid. I have an application which populates a datagrid on the onclick event of a button. The datagrid is bound to an ArrayList which holds the values. ...
0
by: Hollywood | last post by:
I have a DataGrid that is bound to an ArrayList as a SynchArray. The ArrayList is updated by a thread. The thread locks the array list whenever it does an add/remove operation and then tells the...
4
by: Stephen | last post by:
I've got a really annoying problem with a datagrid. I have an application which populates a datagrid on the onclick event of a button. The datagrid is bound to an ArrayList which holds the values. ...
5
by: Matthew Woods | last post by:
bool A = Is this the right place to ask this question? if (A) { Where can i find a good example of an ArrayList bound to a datagrid that automatically updates the grid when the public data...
3
by: Matthew Woods | last post by:
Hi, is there any way to format and order the columns displayed in a datagrid bound to a class that inherits from IBindingList? i have used DataGridTableStyle and added DataGridTextBoxColumns to it...
5
by: nadeem_far | last post by:
Hello All, I have been trying to solve the following issue and it seems like there is no solution available any where and maybe people at Microsoft should may be of some help. I am writing a...
5
by: Dennis | last post by:
I have a class that inherits from DataGrid. I can set the rowheights in a DataGrid by tappig into the "get_Datagridrows" method. However, this does not work for classes that inherit from...
0
by: Michael C# | last post by:
I have found a few samples of using a combobox in a Datagrid on the Web (Windows Forms). While these examples work well for what they do, I need more functionality, and I'd like some advice on the...
1
by: g.o.atkins | last post by:
Hi, I've bound an ArrayList to a datagrid and succesfully managed to display the data via an ItemTemplate column and using <%# Container.DataItem %>. The problem I have however is trying to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.