tags:

views:

777

answers:

4

I'm trying to use a windows forms datagrid (.NET 1.1) to update the elements of a two dimensional array. Using the microsoft documentation, I've been able to get the datagrid to display the array properly.

EDIT: The MS instructions I followed are at http://support.microsoft.com/kb/315786.

class myrow {
   private int a, b;
   public int A {get { return a; } set {a = value;}}
   public int B {get { return b; } set {b = value;}}
}

myrow[] myRows = new myrow[5] {
    new myrow(3,2),
    new myrow(2,2),
    new myrow(1,2),
    new myrow(3,3),
    new myrow(3,1),
}

myDataGrid.SetDataBinding(myRows, "");

I've also got the DataGrid's TableStyle.MappingName property set to "myrow[]".

What's been driving me crazy is that I can't update it. I enter a new value in a cell on the form, say "1123", and hit enter or tab, and the cursor moves to the next cell and the value changes back to the original value.

How can I get it to take the updates?

A: 

This is off the top of my head, but I think you need to implement an event that gets fired when you change a grid cell or click the update button.

Bless Yahu
Haven't been able to find an event that has the information. Can get event for current cell selection changes, but no event I've found will provide an event for item changes. CurrencyManager has an ItemChanged event, but it doesn't seem to fire.
davenpcj
A: 

Unfortunately I can't check it for .NET 1.1, but as for .NET 2.0 control DataGridView which replaced DataGrid, it isn't needed to update data source manually.

Hope this will help you somehow.

Alexander Prokofyev
it's *supposed* to update automatically, but it doesn't.
davenpcj
A: 

There's a workaround, if you change the array to an ArrayList or other collection class, then the updates work.

Not a true answer, because that's still not using the object array, and still doesn't fit well with a regular 2D array of data.

davenpcj
A: 

Off the top of my head, I think you need to ... Upgrade to a more recent version of Visual Studio.

Cheeso
I usually prefer to write for the broadest audience possible. Since mainstream support ended October 2008, you're probably right. MS continues to support .Net 1.1 until July 2015.But at the time I wrote the question, 1.1 was all I had, and I didn't want to download the 354MB for the 2.0 SDK. Or the entire VS2005 setup.
davenpcj