This is a migrated thread and some comments may be shown as answers.

[Solved] Getting index is outside the bounds of the array error whenever trying to access items on RowDrop

4 Answers 547 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 13 Jun 2008, 07:04 PM
Getting this error whenever accessing the grid, this is basically the code, I get an error on both enumerations... I've alse tried using e. DestinationGrid instead of this.radGrid...

protected void radGrid_RowDrop(object sender, GridDragDropEventArgs e)
{
    foreach(GridDataItem gridItem in this.radGrid.MasterTableView.Items)
    {
        //do stuff...
    }

foreach (GridDataItem draggedItem in e.DraggedItems)
    {
           //do stuff
    }

}


 Edit - this grid is in a radajax panel if it makes any difference -

4 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 16 Jun 2008, 02:44 PM
Hello Josh,

It seems that in your case the dragged items/the Items collection of the grid are empty due to some reason and you receive the exception. Can you trace the reason for that or paste your grid declaration along with its code-behind in order to advice you further?

Kind regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Josh
Top achievements
Rank 1
answered on 17 Jun 2008, 01:27 AM

Here are the declarations:



<
telerik:RadGrid ID="rGrid" runat="server" Width="100%" AllowMultiRowSelection="true"

EnableEmbeddedSkins="false" Skin="Black" ImagesPath="../Skins/Black/Grid" AutoGenerateColumns="false"

GridLines="Both" ShowHeader="true" OnRowDrop="rGrid_RowDrop">

<ClientSettings AllowRowsDragDrop="true">

<Selecting AllowRowSelect="true" EnableDragToSelectRows="true" />

</ClientSettings>

<MasterTableView Width="97%" CommandItemDisplay="None" AutoGenerateColumns="false"

DataKeyNames="ID" TableLayout="Auto" HeaderStyle-HorizontalAlign="Center"

HeaderStyle-VerticalAlign="Middle" HeaderStyle-Wrap="false" NoMasterRecordsText="No items.">

<Columns>

<telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID"

Visible="false">

</telerik:GridBoundColumn>

<telerik:GridTemplateColumn DataField="Checked" HeaderText="Show" UniqueName="Checked"

Visible="true" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"

HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ItemStyle-Height="20px"

HeaderStyle-Height="30px">

<ItemTemplate>

<asp:CheckBox runat="server" ID="displayCheckbox" Checked='<%# DataBinder.Eval(Container, "DataItem.Checked") %>' />

</ItemTemplate>

</telerik:GridTemplateColumn>

<telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name"

Visible="true" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Middle"

HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" ItemStyle-Height="20px"

HeaderStyle-Height="30px" ReadOnly="true">

</telerik:GridBoundColumn>

</Columns>

</MasterTableView>

</telerik:RadGrid>



Function to load grid data (it's in a radajax panel):

private void displaySettingsPanelLoad(IPostBackEventHandler source, string eventArgs)

{

DataTable dTable = Function here to get table, I know for sure this works...

this.rGrid.DataSource = metadataTable;

this.rGrid.DataBind();

}

I do have another function to handle updates the grid checkboxes in the code-behind. This is working fine.

0
Princy
Top achievements
Rank 2
answered on 17 Jun 2008, 04:29 AM
Hi Josh,

Try binding the Grid using AdvanceDataBinding techniques. Go through the following demo link for more details.
Advanced data-binding

Thanks
Princy.
0
Josh
Top achievements
Rank 1
answered on 19 Jun 2008, 12:22 AM
That was helpful, I am rebuilding the datasource and binding the grid again and it's working well, thanks.
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Josh
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or