可变变化? [英] Is Variable Changing?

查看:114
本文介绍了可变变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这只返回item1类型?

Why does this return only item1 types?

foreach (DataRow dataRow in dt.Rows)
            {
                if (dataRow["Column1"].ToString().Contains(["ExampleString"])
                {
                    
                    listBox1.Items.Add(dataRow["Column1"] + " " + dataRow["Column2"] + "  " + dataRow["Column3"] + " " + dataRow["Column4"]);

                }
            }


//the above code works perfectly and returns only the rows containing the "ExampleString"


// if i try to use a SelectedText value from a combobox as a string to replace the "ExampleString", (as shown below),the listbox populates with ALL of the rows, not just the ones with the "ExampleString".  




string strFromCombobox = comboBox1.SelectedText;

foreach (DataRow dataRow in dt.Rows)
            {
                if (dataRow["Column1"].ToString().Contains(strFromCombobox)
                {
                    
                    listBox1.Items.Add(dataRow["Column1"] + " " + dataRow["Column2"] + "  " + dataRow["Column3"] + " " + dataRow["Column4"]);

                }
            }

推荐答案

试试这个:

    string strFromCombobox = comboBox1.SelectedValue.ToString();

    string strFromCombobox = comboBox1.SelectedValue.ToString();


这篇关于可变变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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