嗨,它抛出无效。我能找到它为什么会这样。请帮助我。 [英] Hi, It throws null excetion. i could find that why it is happening. pls help me out.

查看:60
本文介绍了嗨,它抛出无效。我能找到它为什么会这样。请帮助我。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void EventArgs(object sender,EventArgs e)

{





KeyEventArgs ke = e as KeyEventArgs;



if(ke.Key == null)

{



if(qty_status == 1)

{

.....

}



其他



....



嗨我需要keyeventargs。所以,我使用上面的方法将eventargs转换为keyeventarge。在ke我第一次得到null。所以我检查了条件if(ke.key == null)。 ke.key只显示null。但它不会进入该条款。它下一步就是例外。并抛出null引用异常。



实际上,我需要检查一下这个。



我正在使用currenctcellchanged事件。所以首先它应该检查选项卡是否由用户显示。如果是,它应该访问一个方法。否则它应该访问下一个方法。 Rougly我写了我需要的东西。但这不正确。请更正以下编码并帮我解决。



if(e.key == key.tab)



$



onemethod();



}



其他



{



另一种方法();



}



注意:我使用了datagrid(即)currentcellchanged事件。



非常感谢!..

private void EventArgs(object sender, EventArgs e)
{


KeyEventArgs ke = e as KeyEventArgs;

if (ke.Key == null)
{

if (qty_status == 1)
{
.....
}

else

....

hi i need keyeventargs . so, i converted eventargs to keyeventarge using like above. in the ke i got null first time. so i checked the condition if(ke.key==null). ke.key shows null only. but it is not going inside the codition. the next step it goes exception. and throws null reference exception.

Actually, i need to check follow this.

i am using currenctcellchanged event. so first it should check tab is appeard by user or not. if it is , it should access one method. otherwise it should access next method. Rougly i have written what i need. but it is not correct. correct this below coding and help me out.

if(e.key==key.tab)

{

onemethod();

}

else

{

another method();

}

Note: i used datagrid (ie) currentcellchanged event.

Thank you so much!..

推荐答案

因为变量 e 不是 KeyEventArgs



当您使用作为关键字时做一个明确的演员。如果变量无法转换为该类型,结果将为 null



如果您将以下内容放入演员的前面,很可能会抛出一个例外:



Because variable e is not of type KeyEventArgs.

When you use the as keyword to do an explicit cast. The result will be null if the variable cannot be cast to that type.

If you put the following in front of the cast, it will most likely thrown an exception:

if(!(e is KeyEventArgs)) throw new InvalidCastException();





如果您做了这样的显式演员,这将是相同的:





This would be the same if you did an explicit cast like this:

KeyEventArgs ke = (KeyEventArgs)e;


您正在施放 EventArgs 对象不正确。 KeyEventArgs Class [ ^ ]是为了响应 KeyDown KeyUp 事件而发送的。
You are casting the EventArgs object incorrectly. The KeyEventArgs Class[^] is sent in response to a KeyDown or KeyUp event.


这篇关于嗨,它抛出无效。我能找到它为什么会这样。请帮助我。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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