Hi,
I am getting one error ,that is
System.ArgumentOutOfRangeException was caught
Message="Index was out of range. Must be non-negative and less than the
size of the collection. Parameter name: index"
while loading/assigning datasource to wingrid.Try...catch section is also not able to
catch this particular error.
I have gone through the site
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.Aspx?ArticleID=5165
but where i need to write these methods?
I tried with this code but still error is coming after trying few
times(50 times) ,It is no so frequent error.
grdInvestor.BeginUpdate() grdInvestor.SuspendRowSynchronization() If grdInvestor.DataSource Is Nothing Then grdInvestor.DataSource = DatabseReturnInvestor grdInvestor.DisplayLayout.Bands(0).Columns("Investor").Width = 350 grdInvestor.DisplayLayout.Bands(0).Columns("Fund").Width = 350 HideExcelGridColumns(grdInvestor) End If grdInvestor.ResumeRowSynchronization() grdInvestor.EndUpdate()
I am also using some events like
grdInvestor_AfterRowUpdate,
grdInvestor_BeforeEnterEditMode
grdInvestor_DoubleClickRow
grdInvestor_InitializeLayout
grdInvestor_InitializeRow
grdInvestor_Click
I am attaching screen shots for reference.
Thanks in advance.
Regards,
Rajesh Kumar
Rajesh,
According to your stack trace, the exception is occuring because there are no bands (i.e. bands(0) is out of range since there are no items in the array). My guess is that since you've called BeginUpdate on the grid, the grid will not have a chance to paint or render, which usually triggers the grid to build its data structure. What I would do is put any code that needs to access columns into the InitializeLayout event of the grid instead of trying to do it directly after assigning the DataSource. You could also try removing the Suspend/ResumeRowSynchronization calls, since I'm not sure that these really have any benefit at this point.
-Matt
Matt,
I was not using BeginUpdate on the grid previously,after going through the link
I placed this code in my coding even then it was coming.Why this is not occuring all the time ?
As you explained I should write these lines at InitializeLayout
grdInvestor.DisplayLayout.Bands(0).Columns("Investor").Width = 350
grdInvestor.DisplayLayout.Bands(0).Columns("Fund").Width = 350
HideExcelGridColumns(grdInvestor)
but i am not sure the above error won't come..any reason you have..?
What is exact solution of this problem Matt.?
I will be thankful if you help me out.
Regards,Rajesh Kumar,India