组合框异常对象实例未发送 [英] combobox exception object instance not sent

查看:60
本文介绍了组合框异常对象实例未发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,我想使用在该组合框中输入的值,例如

  public  < span class =code-keyword> string  Getfirst()
{
string ques = ;

comboBox1.SelectedItem = ;

ques = comboBox1.SelectedItem.ToString();
return ques;



}







< pre lang =cs> if (ss.Getfirst()== 50&& ss.GetSecond()== 4
{
pictureBox1.Image = Loadimage2();
}





但我收到错误

对象引用未设置为对象的实例。在这一行

ques = comboBox1.SelectedItem.ToString();

什么可能是错误的并且解决了这个错误?

解决方案

你需要使用你的调试器。

在有问题的行上放置一个断点,然后当断点被击中时,将鼠标悬停在<$的每个部分上c $ c> comboBox1.SelectedItem.ToString()部分。其中一个将显示null。我怀疑它将是SelectedItem,但只有你肯定会知道,并且只有你使用调试器时才会使用它。

干杯。


可能有问题

你无法获得comboBox1控件


i have a combobox and i want to use value entered in that combobox like

public  string Getfirst()
      {
          string ques = "";

          comboBox1.SelectedItem = "";

          ques = comboBox1.SelectedItem.ToString();
          return ques;



      }



and

if (ss.Getfirst() == "50" && ss.GetSecond() == "4")
                {
                    pictureBox1.Image = Loadimage2();
                }



but i get error
Object reference not set to an instance of an object. on this line
ques = comboBox1.SelectedItem.ToString();
what can be wrong and solution for this error??

解决方案

You need to use your debugger for this.
Place a breakpoint on the line in question and then when the breakpoint gets hit, hover your mouse over each part of the comboBox1.SelectedItem.ToString() parts. One of them will show null. I suspect it will be SelectedItem, but only you will know for sure, and only if you use your debugger as it was intended to be used.
Cheers.


there may be problem that
you are not able to get comboBox1 control


这篇关于组合框异常对象实例未发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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