❔ Copying selected item from list box to another list box (Utilizing data source)
I cant seem to be able to copy one item from a listbox to another, my current code I am attempting is as so
listbox3.items.add(listbox2.selecteditem.tostring());
It is adding an item to my list box, but it reads
System.Data.DataRowview
instead of the selected item text, I think this is due to me populating my initial listbox from a data source.
Is there an easy work around for this? I couldnt seem to find anything like this issue online.12 Replies
This is winforms I suppose; regardless DataRowView has columns you can access data with; probably easiest to cast SelectedItem to DataRowView and access the column you need to get the needed data.
https://learn.microsoft.com/en-us/dotnet/api/system.data.datarowview?view=net-8.0
Correct on the winforums portion; If I were to cast to DataRowView, would I then have access to the properties of that row (In this case the colums of my MDF database table)?
Yah that sounds right
Ah I see
let me give this a shot.
I never think about casting in C#, I usually only work with simple data types.
NB: whatever you’re selecting out; so could be that you don’t have all columns
Makes since.
So did that work?
Yes, it did thank you. This was how I implemented the solution.
It’s a start
Probably good enough for the moment 🙂
For my school assignment, most definitely. I dont ever see myself needing to utilize DataSources in the future honestly.
Why not?
I mean ideally you’re doing some sort of data binding
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.