更好的代码还是任何人都可以解决这个问题? [英] Better code or can any one solve this?

查看:78
本文介绍了更好的代码还是任何人都可以解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到一个错误

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


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;
        }
        /**/
    }


在单击工作流程按钮m时收到此错误..

和m在我的项目中使用动态
这是工作流程课程


while clicking workflow button m getting this error..

and m using dynamic in my project
here is work flow class

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.

推荐答案

您说您在这里遇到错误:

You say you''re getting the error here:

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



这很明显意味着您的TreeView1没有节点.要么在错误的代码周围添加一个检查,以检查TreeView1是否有任何节点,要么在TreeView1中添加一些节点.



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.


我会尝试放置诸如

I would try to put something like

if (TreeView1.Nodes.count > 0)



代替



in place of

/*Root Node - Create*/



看看会发生什么.问题似乎是您的TreeView1对象中没有任何节点(因此消息说索引超出范围).



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).


请添加对treeview节点的检查像对数据表行那样进行计数,并检查错误是否仍然存在.

问候
Praveen
Please add check for treeview''s node count as you did for datatable rows and check if error still persist.

Regards
Praveen


这篇关于更好的代码还是任何人都可以解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆