Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview Manual Update

Status
Not open for further replies.

sakkara

Programmer
Jun 18, 2007
4
AU
Hi,

Due to the complexity of the data, I have to build up the datatable manually and then bind it to a gridview. The process is listed below:-
1. Build data into 2d array array
2. Loop through each row in the array, building a Datarow and adding the datarow to the datatable.
3. Binding the datatable to the gridview.

This works perfect when viewing the data, however I can not update any rows. It gets into the edit mode fine, but when I click update it gives the following error:-
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

The code is listed below:-
Dim UpdateValues(20) As String
Dim UpdateValuesCount As Integer = 0

For CellCount As Integer = 0 To 18
Dim DataControlFieldCell As DataControlFieldCell = TryCast(gvPrincipalPosition.Rows(e.RowIndex).Cells(CellCount), DataControlFieldCell)
gvPrincipalPosition.Columns(CellCount).ExtractValuesFromCell(e.NewValues, DataControlFieldCell, DataControlRowState.Edit, True)
Next

It dies on line 5. Any ideas would be very much appreciated!
 
I would break your 2 liner into multiple lines. setting each value to a variable. then step through the code watching each variable and see exactly where it fails.

I assume this code is within the OnUpdating event of the datagrid since you are referencing e.RowIndex and e.NewValues.

I would also say you are going about this the difficult way. instead of the all the casting, and row index why not use
the OnUpdating like this:
Code:
Dim UpdateValues(20) as string
Dim i as int
while i < e.NewValues.Length
   UpdateValues(i) =  e.NewValues(i)
end while
''use string array

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top