473,425 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

C# question about listbox

I'm new to C# and visual studio
My problem is the following:

I have an access file with foods.
In a form i have a listbox and i have succesfully connected the data source of the listbox with the access file and i get the foods in my listbox
But now i want to copy the items of the listbox to an array
i do that with the following line

listbox1.Items.CopyTo(aa, 0);

but all the values of the array takes the following value "System.Windows.Forms.ListBox + ObjectCollection"
I found the following

By default when you bind the ListBox’s ItemsSource to a collection of objects of a custom type, the ListBox would simply call the object’s ToString() method to determine what to display for each item. The ToString method would normally simply display the type name of the object.
If you instead want a value of a property of the object to be displayed in the listbox, you should set the DisplayMemberPath property of the ListBox to that property name as follows:
<ListBox ItemsSource='{StaticResource myCollection}' DisplayMemberPath='FirstName' />


..but i couldnt figure out how i can make this work (if this is the reason..)

I would really appreciate any help

My code:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleEleme nt;

namespace food1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void pRODUCTSBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.pRODUCTSBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.foodsDataS et);

}

private void Form1_Load(object sender, EventArgs e)
{
this.pRODUCTSTableAdapter.Fill(this.foodsDataSet.P RODUCTS);
object[] aa = new object[80];
listbox1.Items.CopyTo(aa, 0);
textBox1.Text = “ ”+aa[2];
}

}
}
Mar 6 '23 #1
0 1131

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Serge Lacombe | last post by:
Hi, A listbox contains a list of files. Some are writable, others are not. I would like to 'see' that difference (different color or...?). How can it be done? Thanks.
2
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put...
4
by: questions | last post by:
I create a Form and call another class (e.g. class1.cs). (class1.cs) contains a command to call back the Form to display a string variable in a listbox. However, it doesn't works. The listbox gets...
1
by: cloverme | last post by:
I have a couple of questions about coding (using vb.net) to a webform. Thanks in advance for your help. I'm a little new to vb.net, but a VB veteran. 1) When the page loads, how can I...
3
by: Menu Chen | last post by:
See the code below,why my listbox can't refresh after my do the RemoveAt attribute in the event of Button1_Click I have used listbox1.refresh() and listbox1.update() ,but they didn't work any...
1
by: lkp_ajay_mehta | last post by:
plz help.i am beginner of ms access.any thing about listbox,combobox which help me to understand how to create listbox,combobox for working sent to me.
9
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback)....
1
by: saddist | last post by:
Hello, yeah it's me again :P this time I have a question about listbox and opening a report: On a form I have a listbox where I store months. I also have a report where I list names of...
4
by: kimiraikkonen | last post by:
Hi, I have a odd but a known question about listbox. I know listbox control can provide multi-select, multi-extendend selections. But i wonder if this selection type belongs to them or it has...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.