473,396 Members | 2,024 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,396 software developers and data experts.

Array to DataGridView


I have a string arrary that i wish to display in a datagridview but when
i set the datasource to the array the resulting datagridview gives me the
length of the stings not the actual strings.
How do i display the actual strings?

//code
string[] arr = new string[2];
arr[0] = " 1st Item";
arr[1] = " 2nd Item";
dataGridView1.DataSource = arr;

rgds,Steve
Oct 15 '06 #1
1 24041
The datagrid uses reflection to get the properties of the items returned by
the IList implemenation (your array). Since the only public property of the
string is length, then that is what is returns. Here is some code that
should help you get a solution.

ArrayList s = new ArrayList();
s.Add("1st Item");
s.Add("2nd Item");
GridView1.DataSource = s.ToArray(typeof(string));
GridView1.DataBind();

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
"Steve" <cc******@bigpond.net.auwrote in message
news:A4*******************@news-server.bigpond.net.au...
>
I have a string arrary that i wish to display in a datagridview but
when i set the datasource to the array the resulting datagridview gives me
the length of the stings not the actual strings.
How do i display the actual strings?

//code
string[] arr = new string[2];
arr[0] = " 1st Item";
arr[1] = " 2nd Item";
dataGridView1.DataSource = arr;

rgds,Steve

Oct 15 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob | last post by:
Dear All, I am having a few issues with DataGridViews. Here is what I have. In a windows form I have added a DataGridView. My data is stored in an array of instances of a class with several...
0
by: Marc Gravell | last post by:
I have a remote web-method that returns an array of strongly-typed objects; on the client this gets a schema-based representation (as per wsdl.exe). I have an array of (for instance) SearchResult...
3
by: nasser | last post by:
Hi, I'm writting a programe using C# that reads data from file and then store these data in array and display these data from the array to the datagridview. this the frist part. the second part is ...
0
by: freddycoal | last post by:
Hi, I would like know, how transform a datagridview row to an array. Exist commands for make this?. I have CVS file, I read line to line, but I would like asign this array (one line in my...
0
by: Mark Jerde | last post by:
VS 2005 SP1. Googled without success. I have an array of structs, and some of the elements are arrays of structs. E.g., ------------------------------------- public struct foobar { public int...
9
by: active | last post by:
I need a control that displays a grid of rectangles. That is, like a brick wall except the rectangles are lined up. In VB6 I used such a control (may have been called FlexGrid but I'm not...
0
by: bharathi228 | last post by:
hi, how to assign a array as datasource to datagridview in vb.net. my code is Dim intarray(mblndigital_inputs) As Integer mblndigital_inputs.Copyto(intarray, 0) Array.Reverse(intarray)
3
by: bharathi228 | last post by:
hi, how to assign a array as datasource to datagridview in vb.net. my problem is iam having an array with 60 values
0
by: starlight849 | last post by:
Hello guys and gals. As always any help is much appreciated. I am at a dilema. I am filling a datagridview with very lengthy results. Roughly 60k rows on average. I am filling them via an oracle...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.