数据从组合框到网格视图 [英] data from combobox to grid view

查看:95
本文介绍了数据从组合框到网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

在这里我创建一个函数
当我单击组合框数据ID的任何项目时,将在数据网格视图中显示

而这些数据我必须保存在其他表中


这是我的功能


hi to all!

here i create one function
when i click on any item of combobox data id is displayed in data grid view

and that data i have to save in some other table


here is my function


private void comboBoxSelectMRF_SelectedIndexChanged(object sender, EventArgs e)
       {
           try
           {
               string a = comboBoxSelectMRF.SelectedItem.ToString();
               int b = Convert.ToInt32(a);
               SecurityModule.FillDataInGridView_umrf("proc_mrf_discription_umrf", b, dataGridViewUMRF);
           }
           catch (Exception ax)
           {
               MessageBox.Show(ax.Message);
           }
       }




错误是

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


如何解决

[edit]添加了代码块,将我的内容作为纯文本..."选项已禁用-OriginalGriff [/edit]




the error is

"object refrence not set to an instance of an object"


how to solve it

[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]

推荐答案

难以快速查看,但请尝试检查是由哪条线生成的.
comboBoxSelectMRF.SelectedItem开头-如果未选择任何项目,则该字段可以为null-然后ToString可能引发错误.或者您可能启用了多选,在这种情况下可能会为null.
Difficult to tell from a quick look, but try checking which line is generating it.
Start with comboBoxSelectMRF.SelectedItem - If no item is selected, it could be null - ToString could then throw the error. Or you may have multi select enabled, in which case it would likely by null.


我不知道您的ComboBox中是什么类型的项目.通常,如果它包含纯字符串,则应该能够获取字符串值,但我认为您没有字符串.例如,如果您正在使用WPF,并且您的ComboBox包含TextBlocks作为Items,则必须进行一些强制转换,例如:

What I don''t know is what type of items is in your ComboBox. Normally, if it contain pure strings, you ought to be able to get the string value out but I dont think you have strings. For example if you''re working with WPF and your ComboBox contains TextBlocks as Items, you have to do some casting like:

string a = ((TextBlock)comboBoxSelectMRF.SelectedItem).Text.ToString();


和如果未选择任何项目,则可能为null-ToString可能会引发错误.或者您可能启用了多选,在这种情况下,很可能为null."如 OriginalGriff [


and "If no item is selected, it could be null - ToString could then throw the error. Or you may have multi select enabled, in which case it would likely by null." as said by OriginalGriff[^]

If your Comboox contains something else, then it''s better to let us know what exactly you''re binding your ComboBox to so that we can provide precise solution


这篇关于数据从组合框到网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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