两个句子之间的差异 [英] difference between two sentences

查看:93
本文介绍了两个句子之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


希望您能帮助我了解这两个句子的区别

Hi
I hope you can help me to know the difference between these two sentences

something=((DataRowView)listBox1.SelectedItem).Row.ItemArray[0].ToString();




and

something = listBox1.SelectedValue.ToString();

推荐答案

假设您的代码行都很好,'' ve数据绑定到数据视图.第二行代码只是返回所选项目的值"(即,您已表示为ValueMember的任何内容).第一个返回到控件的数据绑定,找到所选项目的行,并在第一列中返回值-该值可能是也可能不是值或显示成员,具体取决于您的操作方式
Both your code lines are fine, assuming you''ve data bound to a dataview. The second line of code simply returns the "value" of the selected item (that is, whatever you''ve indicated as the ValueMember). The first reaches back into the data binding for your control, finds the row for the selected item, and returns the value in the first column--that value might or might not be the value or display member, depending on how you''ve coded it.


(((DataRowView)listBox1.SelectedItem).Row.ItemArray [0] .ToString();
这甚至正确吗?我不信.

列表框的所选项目将为ListItem类型.您正在尝试将其转换为DataRowView.应该存在无法转换表达式错误.

第二个看起来不错-有效的代码行.
((DataRowView)listBox1.SelectedItem).Row.ItemArray[0].ToString();
Is this even CORRECT? I doubt that.

Listbox''s selected item would be of type ListItem. You are trying to cast it into DataRowView. There should be cannot cast expression error.

Second one looks ok - a valid code line.


关于SelectedValueSelectedItem之间的区别,您可以阅读以下链接:http://bea.stollnitz.com/blog/?p=9

For the difference between SelectedValue and SelectedItem, you can read this link: http://bea.stollnitz.com/blog/?p=9


这篇关于两个句子之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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