473,516 Members | 2,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24086
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
1791
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 properties. Then I simply set the data source property of the DataGridView to that array. The data is displayed but there are a few issues: 1) The...
0
1172
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 objects; this has some simple properties (which work fine), and some that are more complex - i.e. a Customer property that is of type Person, which...
3
17887
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 I would like to get help how can add row in datagridview so, when user determine new row and usually this new row the last one and start enters data...
0
1140
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 array) directly to my datagridview row. Thanks in advance for any help. Freddy Coal
0
1416
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 ID; public string Name; public foo FooFields; public bar BarFields;
9
1647
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 sure.) I did see the DataGrid control but that seems oriented to DB usage. It's probably much more complex than what I need, but I'm not sure about...
0
1200
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
27898
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
1048
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 database using a table adapter. The records then have a filter placed on them in the datagridview so the results displayed are a bit different. My...
0
7279
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7412
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7143
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7549
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5112
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3268
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3265
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
494
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.