| | |
Datagrid - no value at index ### error when scroll and sort
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
I have a form with a datagrid on it. If I 1) scroll to the right to a field that wasn't originally displayed on the grid 2) click on the header of that field to sort the datagrid 3) then scroll down to bottom area of the datagrid and selects a cell that is in the bottom righthand side of the grid (basically one that wasn't shown when datagrid 1st came up) 4) press a button that reloads the datagrid --- An error is generated "IndexOutOfRangeException: No value at index ###". The number(###) always changes. See full message below. I've tried just scrolling without sorting, and it had no error. If I sort without scrolling, it had no error. If I squish the fields over to the left so that the field I'm sorting with is on the original data grid -- then sort -- then scroll down to the bottom right cell --- it did not have an error. It seems to be a problem if I'm sorting on a colum is off to the right and I select a field that is below the area that was originally display. Does anyone have any ideas? I've included the error message and the area of code that reloads the datagrid. Line 3148 is dgForm1.DataSource = mydataview.
------------------------------------------------------------------------------------------------------------------------------
VB.NET Syntax (Toggle Plain Text)
System.IndexOutOfRangeException: No value at index 49. at System.Windows.Forms.CurrencyManager.get_Item(Int3 2 index) at System.Windows.Forms.DataGridColumnStyle.GetColumn ValueAtRow(CurrencyManager source, Int32 rowNum) at System.Windows.Forms.DataGridTextBoxColumn.Edit(Cu rrencyManager source, Int32 rowNum, Rectangle bounds, Boolean readOnly, String instantText, Boolean cellIsVisible) at System.Windows.Forms.DataGrid.Edit(String instantText) at System.Windows.Forms.DataGrid.Edit() at System.Windows.Forms.DataGrid.set_HorizontalOffset (Int32 value) at System.Windows.Forms.DataGrid.LayoutScrollBars() at System.Windows.Forms.DataGrid.ComputeLayout() at System.Windows.Forms.DataGrid.OnLayout(LayoutEvent Args levent) at System.Windows.Forms.Control.PerformLayout(Control affectedControl, String affectedProperty) at System.Windows.Forms.Control.PerformLayout() at System.Windows.Forms.DataGrid.OnColumnCollectionCh anged(Object sender, CollectionChangeEventArgs e) at System.Windows.Forms.DataGridTableStyle.OnColumnCo llectionChanged(Object sender, CollectionChangeEventArgs e) at System.Windows.Forms.GridColumnStylesCollection.On CollectionChanged(CollectionChangeEventArgs ccevent) at System.Windows.Forms.GridColumnStylesCollection.Co lumnStylePropDescChanged(Object sender, EventArgs pcea) at System.Windows.Forms.DataGridColumnStyle.OnPropert yDescriptorChanged(EventArgs e) at System.Windows.Forms.DataGridColumnStyle.set_Prope rtyDescriptor(PropertyDescriptor value) at System.Windows.Forms.DataGridTextBoxColumn.set_Pro pertyDescriptor(PropertyDescriptor value) at System.Windows.Forms.DataGrid.PairTableStylesAndGr idColumns(CurrencyManager lm, DataGridTableStyle gridTable, Boolean forceColumnCreation) at System.Windows.Forms.DataGrid.SetDataGridTable(Dat aGridTableStyle newTable, Boolean forceColumnCreation) at System.Windows.Forms.DataGrid.Set_ListManager(Obje ct newDataSource, String newDataMember, Boolean force, Boolean forceColumnCreation) at System.Windows.Forms.DataGrid.Set_ListManager(Obje ct newDataSource, String newDataMember, Boolean force) at System.Windows.Forms.DataGrid.set_DataSource(Objec t value) at SalesRaptorPC.form1.loaddatagrid() in C:\SalesRaptor PC\SalesRaptorPC\Form1.vb:line 3148
VB.NET Syntax (Toggle Plain Text)
Dim sqlConn As SqlConnection = New SqlConnection(Connection) Try sqlConn.Open() Dim sqlcomm AsNew SqlDataAdapter("salesRaptor_GetActivityPC", sqlConn) sqlcomm.SelectCommand.CommandType = CommandType.StoredProcedure Dim workParam As SqlParameter = New SqlParameter workParam = sqlcomm.SelectCommand.Parameters.Add("@Rep", SqlDbType.VarChar, 25) If chkAllReps.CheckState = CheckState.Checked Then sqlcomm.SelectCommand.Parameters("@Rep").Value = Rep_ID.ToString Else sqlcomm.SelectCommand.Parameters("@Rep").Value = txRepID.Text EndIf workParam.Direction = ParameterDirection.Input workParam = sqlcomm.SelectCommand.Parameters.Add("@Status", SqlDbType.VarChar, 25) sqlcomm.SelectCommand.Parameters("@Status").Value = "P" workParam.Direction = ParameterDirection.Input Dim tempdate1 As DateTime = MthCalForm1.SelectionStart.Date + " 12:00:01 AM" workParam = sqlcomm.SelectCommand.Parameters.Add("@DateLower", SqlDbType.SmallDateTime) If actdelsw <> "DELINQUENT" Then sqlcomm.SelectCommand.Parameters("@DateLower").Value = tempdate1 workParam.Direction = ParameterDirection.Input workParam = sqlcomm.SelectCommand.Parameters.Add("@DateUpper", SqlDbType.SmallDateTime) If actdelsw = "DELINQUENT" Then Dim tempdate2 AsDate = Now() sqlcomm.SelectCommand.Parameters("@DateUpper").Value = tempdate2 Else Dim tempdate2 AsDate = MthCalForm1.SelectionEnd.Date + " 11:59:59 PM" sqlcomm.SelectCommand.Parameters("@DateUpper").Value = tempdate2 EndIf workParam.Direction = ParameterDirection.Input workParam = sqlcomm.SelectCommand.Parameters.Add("@Delinquent", SqlDbType.VarChar, 1) If actdelsw = "DELINQUENT" Then sqlcomm.SelectCommand.Parameters("@Delinquent").Value = "D" Else sqlcomm.SelectCommand.Parameters("@Delinquent").Value = "A" EndIf workParam.Direction = ParameterDirection.Input workParam = sqlcomm.SelectCommand.Parameters.Add("@WholeTeam", SqlDbType.VarChar, 1) If chkAllReps.CheckState = CheckState.Checked Then sqlcomm.SelectCommand.Parameters("@WholeTeam").Value = "Y" Else sqlcomm.SelectCommand.Parameters("@WholeTeam").Value = "N" EndIf workParam.Direction = ParameterDirection.Input workParam = sqlcomm.SelectCommand.Parameters.Add("@Include_Inactive", SqlDbType.VarChar, 1) sqlcomm.SelectCommand.Parameters("@Include_Inactive").Value = "N" workParam.Direction = ParameterDirection.Input Dim ds AsNew DataSet sqlcomm.Fill(ds, "ACTIVITYGRID") 'holds data from query ds.Tables(0).Columns(17).ColumnMapping = MappingType.Hidden ' hide the record status field Dim x = ds.Tables(0).Rows.Count() Dim mydatatable As DataTable = ds.Tables(0) 'table name Dim mydataview As DataView = mydatatable.DefaultView mydataview.Sort = "Date / Time" 'sort table dgForm1.DataSource = mydataview 'binds data to grid Dim ts1 AsNew DataGridTableStyle ' change column widths ts1.MappingName = "ACTIVITYGRID" Try dgForm1.TableStyles.Add(ts1) ts1.GridColumnStyles(0).Width = 130 ' change width of date/time fld ts1.GridColumnStyles(1).Width = 150 ' change width of prospect name ' date datetime fields to show time Dim dgtbc As DataGridTextBoxColumn dgtbc = CType(dgForm1.TableStyles(0).GridColumnStyles(0), DataGridTextBoxColumn) IfNot dgtbc IsNothingThen dgtbc.Format = "g" EndIf dgtbc = CType(dgForm1.TableStyles(0).GridColumnStyles(7), DataGridTextBoxColumn) IfNot dgtbc IsNothingThen dgtbc.Format = "g" EndIf Catch EndTry ts1.DataGrid.Refresh() Try ts1.DataGrid.Select(0) Catch EndTry sqlConn.Close() Catch tt As Exception Errmsg = tt.ToString EventSW = "Y" errormsg() ' display error msg sqlConn.Close() Finally sqlConn.Close() EndTry Dim numRows AsInteger = dgForm1.BindingContext(dgForm1.DataSource, dgForm1.DataMember).Count txRecCount.Text = "Count: " + CStr(numRows.ToString) If (dgForm1.CurrentRowIndex < numRows) And (dgForm1.CurrentRowIndex > -1) Then Entityid = CStr(dgForm1(dgForm1.CurrentRowIndex, 13).ToString) 'store current entity id Prospid = CStr(dgForm1(dgForm1.CurrentRowIndex, 12).ToString) 'store current prospect id activityrepid = CStr(dgForm1(dgForm1.CurrentRowIndex, 17).ToString) 'store current activity rep id Contactid = CStr(dgForm1(dgForm1.CurrentRowIndex, 15).ToString) 'store current contact id ActContid = CStr(dgForm1(dgForm1.CurrentRowIndex, 14).ToString) 'store current activity id activitypriority = CStr(dgForm1(dgForm1.CurrentRowIndex, 6).ToString) 'store current activity priority ActivityNotes = CStr(dgForm1(dgForm1.CurrentRowIndex, 3).ToString) 'store current regarding EndIf validateEntityID() getprospectinfo() ' get prospect information getcontactinfo() ' get contact information If tb1.Visible = TrueThen showtabprospectinfo() ' display info on prospect tab EndIf If tb2.Visible = TrueThen showtabcontactinfo() ' display info on contact tab EndIf If tb3.Visible = TrueThen showtabspousechildreninfo() ' display info on spouse children tab EndIf If tb4.Visible = TrueThen showtabhistoryinfo() ' display info on history tab EndIf If tb5.Visible = TrueThen showtabmachinelisting() ' display info on machine listing tab EndIf If tb6.Visible = TrueThen showtabnotes() ' display info on notes tab EndIf If tb7.Visible = TrueThen showtabcompetitormachines() ' display info on competitor machine listing tab EndIf showinqbuttons() ' display inq tab
•
•
Join Date: Sep 2006
Posts: 1
Reputation:
Solved Threads: 0
I had the same problem. I would bind a datagrid to 65 rows of data. I'd scroll down to the end of the list and select a cell, perhaps in row 62. I'd then click on a control outside the grid that would cause a re-bind the grid. The new underlying collection of items had less than 65 items, perhaps 50 rows. After re-binding the grid the DataGridTextBoxColumn edit method would fire, but it still had the old row number of the current cell (in this case rowNum would be 62). This would cause a No Value at Index 62 error, because this row no longer exists in the underlying collection. I fixed the problem by inserting the following code before the rebind.
By setting this property to nothing you're eliminating the call to edit that occurs after the binding. Hope this helps.
Bob
VB.NET Syntax (Toggle Plain Text)
MyDataGrid.CurrentCell = Nothing
By setting this property to nothing you're eliminating the call to edit that occurs after the binding. Hope this helps.
Bob
•
•
•
•
I have a form with a datagrid on it. If I 1) scroll to the right to a field that wasn't originally displayed on the grid 2) click on the header of that field to sort the datagrid 3) then scroll down to bottom area of the datagrid and selects a cell that is in the bottom righthand side of the grid (basically one that wasn't shown when datagrid 1st came up) 4) press a button that reloads the datagrid --- An error is generated "IndexOutOfRangeException: No value at index ###". The number(###) always changes. See full message below. I've tried just scrolling without sorting, and it had no error. If I sort without scrolling, it had no error. If I squish the fields over to the left so that the field I'm sorting with is on the original data grid -- then sort -- then scroll down to the bottom right cell --- it did not have an error. It seems to be a problem if I'm sorting on a colum is off to the right and I select a field that is below the area that was originally display. Does anyone have any ideas? I've included the error message and the area of code that reloads the datagrid. Line 3148 is dgForm1.DataSource = mydataview.
![]() |
Similar Threads
- testing for datachanged in datagrid (Visual Basic 4 / 5 / 6)
- datagrid header height problem (ASP.NET)
- Native Error 00008 (Windows NT / 2000 / XP)
- How can i retrieve data after i logod on..... (ASP.NET)
- Error trapping while reading windows XP registry entries (Python)
- Quick Sort Program (C)
- Parse Error in PHP (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: pls give some idea! remote install
- Next Thread: TableAdapter Update Method
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component crystalreport data database datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project read remove save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





