Windows窗体listbox.selecteditem显示" System.Data.DataRowView"而不是实际值 [英] Windows forms listbox.selecteditem displaying "System.Data.DataRowView" instead of actual value

查看:531
本文介绍了Windows窗体listbox.selecteditem显示" System.Data.DataRowView"而不是实际值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建在Visual Studio 2010年Windows窗体应用程序,我有其中有一个表'ResearcherInfo。Access数据库

I am creating a Windows form application in Visual Studio 2010. I have an Access database which has a table 'ResearcherInfo'.

在我的Windows窗体,我有获得与此表的列名研究员名的内容填充列表框。

In my windows form, I have a listbox which gets populated with the contents of the column name 'Researcher Name' of this table.

然而,当我试图让该文本框的选定项目,它只返回我一个空值或有时System.Data.DataRowView取决于我如何访问它。

However when I try to get the selected items of this text box, it only returns me a null value or sometimes System.Data.DataRowView depending on how I access it

我曾尝试

    string name = projectmembers_lst.SelectedItem.ToString();

而当我将鼠标悬停在projectme​​mbers_lst'字调试,它正确地显示我projectme​​mbers_lst = {=的SelectedItem杰罗姆}

While debugging when I hover the mouse over the 'projectmembers_lst' word, it correctly shows me projectmembers_lst = {SelectedItem = "Jerome"}

但悬停在字符串'名',它显示NAME =System.Data.DataRowView

but on hovering over the string 'name', it shows "name = "System.Data.DataRowView""

我甚至试图复制到一个数组

i even tried copying to an array

    foreach (Object selecteditem in projectmembers_lst.SelectedItems)
    {

        object[] objCollection = new object[projectmembers_lst.SelectedItems.Count];

        projectmembers_lst.SelectedItems.CopyTo(objCollection, 0);

        MessageBox.Show(objCollection[0] as string);
    }

没有得到我所选择的项目。我不知道什么是错在这里。

Nothing gets me the selected items. I am not sure what is wrong here.

填充列表框:

1)我有添加的访问表ResearcherInfo。作为Web表单应用程序的数据源。

1) I have the added the access table 'ResearcherInfo'. as a data source for the web form application.

2)在列表框的属性,数据源选项卡下,我已经挂此表并给出列表框的显示部件和价值成员属性作为表的列名研究员名称。

2) In the properties of the Listbox, under the Datasource tab, I have linked this table and given the display member and value member property of the Listbox as the column name 'Researcher Name' of the table.

所以基本上我的列表框中显示从研究员信息表中的研究员名称。连接是一个快照。

So basically my Listbox displays the Researcher Names from the Researcher info table. attached is a snap shot.

推荐答案

没有看到你是如何填充它,它是很难猜测。

without seeing how you're populating it, it's tough to guess.

尝试((objCollection [0]作为DataViewRow)[0]作为字符串

try ((objCollection[0] as DataViewRow)[0] as string

这篇关于Windows窗体listbox.selecteditem显示" System.Data.DataRowView"而不是实际值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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