以编程方式禁用MenuStrip中的项目 [英] Disable Items from MenuStrip pro-grammatically

查看:78
本文介绍了以编程方式禁用MenuStrip中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team,



我有DataReader,其中存储了ToolStripMenuItem的名称。

我要禁用所有ToolStripMenuItem哪个在这个DataReader中。

我有以下代码 -



Hello Team,

I have DataReader in which Names of ToolStripMenuItem has been stored.
I want to Disable all the ToolStripMenuItem which are in this DataReader.
I have below code -

while(dr.Read())
            {

                menuStrip1.Items[dr[0].ToString()].Visible = false;
            }





但我收到错误,因为对象引用未设置为对象的实例



请帮助。



But I am getting error as "object reference is not set to an instance of an object"

Please help.

推荐答案

对象引用未设置为对象的实例



当您尝试使用属性或调用null对象的方法时,会发生此错误。更多细节:此处 [ ^ ]



Visual Studio DEBUGGER的简单使用可以告诉你对象因为它正在发生。只需查看堆栈跟踪并将调试器放在该行上即可。检查该行的对象,看看是否有任何一个为null,并且您正在尝试使用该对象属性。处理相同。
Object reference not set to an instance of an object

This error happens when you try to use a property or call a method of an object that is null. More details: here[^]

A simple use of Visual studio DEBUGGER can tell you the object because of which it is happening. Just look at the stack trace and put a debugger on that line. Check the objects of that line and see if any one is null and you are trying to use that objects property. Handle the same.


这篇关于以编程方式禁用MenuStrip中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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