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

Problem programmatically adding buttons in version 2008.1 619

3 Answers 85 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Dave Miller
Top achievements
Rank 2
Dave Miller asked on 23 Jun 2008, 06:03 PM
I have spent a bit of time trying to upgrade a project to version 2008.1 619 but have been getting this error:

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
   System.Collections.ArrayList.get_Item(Int32 index) +2748189
   System.Web.UI.StateManagedCollection.System.Collections.IList.get_Item(Int32 index) +9
   Telerik.Web.StronglyTypedStateManagedCollection`1.get_Item(Int32 index) +20

I have traced it down to the line: "RadEditor1.Tools[0].Tools.Insert(0, custom1);"

in

EditorTool custom1 = new EditorTool();
custom1.Name = "CustomSave";
custom1.ShortCut = "CTRL+1";
RadEditor1.Tools[0].Tools.Insert(0, custom1);

The help file also shows adding a button using the code below which also creates the error

EditorTool tool = new EditorTool("Bold");
tool.Type = EditorToolType.Button;
RadEditor1.Tools[0].Tools.Add(tool);

Has something been changed or is this a bug to be resolved. Any help would be greatly appreciated.

Thanks,
Dave

3 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 24 Jun 2008, 11:14 AM
Hi Dave,

By default, RadEditor loads its internal ToolsFile.xml file with predefined tools and modules. In the latest version, we made the toolsfile.xml to be loaded on PreRender, but in the old one the tools and modules were loaded on Init, which is to early in the editor's life cycle.

If you want to dynamically access, add or remove tools and modules in the new editor, you should call the new editor's EnsureToolsFileLoaded() method and everything should work fine, e.g.


protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        EditorTool tool = new EditorTool("Bold");
        tool.Type = EditorToolType.Button;
        RadEditor1.EnsureToolsFileLoaded();
        RadEditor1.Tools[0].Tools.Add(tool);

    }
}

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dave Miller
Top achievements
Rank 2
answered on 25 Jun 2008, 03:12 AM
Rumen,

Thanks for the reply.
 
Indeed adding "EnsureToolsFileLoaded()" was all that was needed.

This may be a good thing to add to the new manual  under the "Buttons" section as it still shows the old method.

Best regards,
Dave
0
Rumen
Telerik team
answered on 25 Jun 2008, 12:38 PM
Hi Dave,

Thank you for your suggestion.

We are currently updating RadEditor's documentation and we will provide information about the new EnsureToolsFileLoaded method.

Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Editor
Asked by
Dave Miller
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Dave Miller
Top achievements
Rank 2
Share this question
or