Click here to Skip to main content
15,921,203 members
Home / Discussions / C#
   

C#

 
GeneralRe: Create a static class to return properties Pin
Richard Deeming7-Sep-16 6:59
mveRichard Deeming7-Sep-16 6:59 
Questionhow to add localdb in console apps using vs2013 Pin
Tridip Bhattacharjee5-Sep-16 23:18
professionalTridip Bhattacharjee5-Sep-16 23:18 
AnswerRe: how to add localdb in console apps using vs2013 Pin
OriginalGriff5-Sep-16 23:31
mveOriginalGriff5-Sep-16 23:31 
AnswerRe: how to add localdb in console apps using vs2013 Pin
ZurdoDev6-Sep-16 4:12
professionalZurdoDev6-Sep-16 4:12 
GeneralRe: how to add localdb in console apps using vs2013 Pin
Eddy Vluggen6-Sep-16 5:20
professionalEddy Vluggen6-Sep-16 5:20 
GeneralRe: how to add localdb in console apps using vs2013 Pin
ZurdoDev6-Sep-16 5:53
professionalZurdoDev6-Sep-16 5:53 
Questionreceive values from a listbox Pin
eli stein2005-Sep-16 6:05
eli stein2005-Sep-16 6:05 
AnswerRe: receive values from a listbox Pin
Dave Kreskowiak5-Sep-16 6:50
mveDave Kreskowiak5-Sep-16 6:50 
"Trying to receive values from a listbox"?

Are you trying to use a listbox to transfer values from one part of your program to another? This is bad practice.

Controls should never be used as a transport mechanism for data. Controls, like a ListBox, are a conduit through which you display parts of your data model to the user and are also used to get data from the user.

Since you're not getting the list of selected items from a user this leads me to believe you're doing something you should not be doing while trying to manage your data model.

A ListBox manages its items using a ObjectCollection class, which is essentially just a List<object>. What you did, when you added items to the ListBox, is added a bunch of DataRowView objects to it. When the ListBox displays these items, it called .ToString() on each of them to get some kind of text to display.

To convert the items in this list to a list of strings, you need to get an appropriate value of a field in each DataRowView. What happens in your code is that the objects in the ListBox are all cast to Object, which really doesn't have any methods or properties on them. The default .ToString() implentation of Object just returns the underlying type name. That's where you're getting the "System.Data.DataRowView" string from.

In order to treat these objects as a type you can actually do something with, you have to cast the objects to the type you can work with, instead of .OfType<object> it should be .OfType<DataViewRow>. Now you've got the methods and properties of a DataViewRow object to work with and your Select() code can be changed to pick an appropriate field/property to get a value from and return an actual value string instead of the type name.
A guide to posting questions on CodeProject

Click this: Asking questions is a skill.
Seriously, do it.

Dave Kreskowiak

GeneralRe: receive values from a listbox Pin
eli stein2005-Sep-16 7:25
eli stein2005-Sep-16 7:25 
AnswerRe: receive values from a listbox Pin
Maciej Los5-Sep-16 19:41
mveMaciej Los5-Sep-16 19:41 
SuggestionRe: receive values from a listbox Pin
Richard Deeming6-Sep-16 1:58
mveRichard Deeming6-Sep-16 1:58 
GeneralRe: receive values from a listbox Pin
Maciej Los6-Sep-16 3:36
mveMaciej Los6-Sep-16 3:36 
QuestionC# Pin
Member 123725154-Sep-16 8:25
Member 123725154-Sep-16 8:25 
AnswerRe: C# Pin
Pete O'Hanlon4-Sep-16 10:09
mvePete O'Hanlon4-Sep-16 10:09 
AnswerRe: C# Pin
Dave Kreskowiak4-Sep-16 12:34
mveDave Kreskowiak4-Sep-16 12:34 
GeneralRe: C# Pin
Richard Deeming5-Sep-16 2:12
mveRichard Deeming5-Sep-16 2:12 
AnswerRe: C# Pin
OriginalGriff4-Sep-16 19:57
mveOriginalGriff4-Sep-16 19:57 
AnswerGreat subject Pin
Luc Pattyn5-Sep-16 3:42
sitebuilderLuc Pattyn5-Sep-16 3:42 
GeneralRe: Great subject Pin
Pete O'Hanlon5-Sep-16 4:06
mvePete O'Hanlon5-Sep-16 4:06 
AnswerRe: C# Pin
#realJSOP6-Sep-16 1:36
professional#realJSOP6-Sep-16 1:36 
Questionjson attribute for ienumerable items Pin
Raghavendra.Kodimala2-Sep-16 23:05
professionalRaghavendra.Kodimala2-Sep-16 23:05 
AnswerRe: json attribute for ienumerable items Pin
Richard MacCutchan3-Sep-16 0:33
mveRichard MacCutchan3-Sep-16 0:33 
AnswerRe: json attribute for ienumerable items Pin
Richard Deeming5-Sep-16 2:11
mveRichard Deeming5-Sep-16 2:11 
Questionshows the insert and read only mode of form view main page dynamically doesn`t work in insert Pin
Member 126153702-Sep-16 20:28
Member 126153702-Sep-16 20:28 
SuggestionRe: shows the insert and read only mode of form view main page dynamically doesn`t work in insert Pin
Richard Deeming5-Sep-16 2:10
mveRichard Deeming5-Sep-16 2:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.