Click here to Skip to main content
15,915,702 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi m getting one error
SQL
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

C#
protected void ChangeNodeColorOfTreeView(TreeView treeViewWorkflow, String DocTypeText, Boolean isRecreate)
    {
        ChangeNodeColorOfTreeView(treeViewWorkflow.Nodes, DocTypeText, isRecreate);

        /*Root Node - Create*/
        {
            string varText = TreeView1.Nodes[0].Text;//this line error
            varText = varText.Replace("<span style='color: blue;'>", "<span style='color: blue;'>");
            varText = varText.Replace("<span style='color: black;'>", "<span style='color: blue;'>");
            TreeView1.Nodes[0].Text = varText;
        }
        /**/
    }

while clicking workflow button m getting this error..

and m using dynamic in my project
here is work flow class
C#
public void WorkFlowSelection(bool IsAction)
    {
        WorkflowBLL objWFBLL = new WorkflowBLL();
        DataTable dt = new DataTable();
        dt = objWFBLL.GetWorkFlowRights(SessionManager.CurrentDocType);

        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["dtWorkFlow"].ToString() != string.Empty)
            {
                if (dt.Rows[0]["dtWorkFlow"].ToString() == "M")
                {
                    toolBar.ShowManualWorkFlowButton = true;
                    if (IsAction)
                    {
                        toolBar.ShowForwardButton = true;
                    }


                    toolBar.ShowForwardButton = false;
                }
            }
            if (dt.Rows[0]["dtWorkFlow"].ToString() == "P")
            {
                if (IsAction)
                {
                    toolBar.ShowPredefinedWorkFlowButton = false;
                    toolBar.ShowForwardButton = false;
                }
                else
                {
                    toolBar.ShowPredefinedWorkFlowButton = true;
                }
            }
        }


    }


can any one solve this?thanks
or suggest me.
Posted
Updated 17-Apr-12 0:27am
v2

You say you're getting the error here:

C#
string varText = TreeView1.Nodes[0].Text;//this line error


Which means quite clearly that your TreeView1 has no nodes. Either add a check around your faulty code that checks if TreeView1 has any nodes, or add some nodes to TreeView1.
 
Share this answer
 
I would try to put something like

C#
if (TreeView1.Nodes.count > 0)


in place of

C#
/*Root Node - Create*/


and see what happens. The problem seems to be that there isn't any node in your TreeView1 object (hence the message saying that index was out of range).
 
Share this answer
 
v2
Comments
ythisbug 17-Apr-12 7:22am    
thanks dude
Please add check for treeview's node count as you did for datatable rows and check if error still persist.

Regards
Praveen
 
Share this answer
 
C#
string varText=string.Empty;
if(TreeView1.Nodes.Count > 0)
{
varText=TreeView1.Nodes[0].Text;//this line error
}
 
Share this answer
 
If the line that is giving you the error is
C#
TreeView1.Nodes[0].Text;//this line error
then this is telling you that you have no items in TreeView1.Nodes. If you put a breakpoint on this line, and debug your application, when you reach this line, right click on the Nodes element and select QuickWatch from the context menu. You can then inspect what's in TreeView1.Nodes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900