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
Thanks.
Well , I ll code your recommended approach,hopefully it will solve my rare occuring problem.
Rajesh Kumar,
India
I don't know what the proper solution of the problem would be because I'm not sure of the cause. The reason that I said to move the code to the InitializeLayout event is because that event is fired when the grid has defined its columns based on what it could determine from the data source, so it's a much safer approach that placing the code immediately after setting the data source; in fact, using the InitializeLayout event is the recommended approach for performing any customization on the grid after binding, since this event will always fire anytime you bind the grid to a data source. My guess was that your problem stemmed from a timing issue in your application, and the InitializeLayout event is a good approach to follow regardless.
Also, instead of having "grdInvestor.DisplayLayout.Bands(0)..." in the InitializeLayout event, you should use "e.Layout.Bands(0)...".