This is a migrated thread and some comments may be shown as answers.

Bind to array

4 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yousef
Top achievements
Rank 2
Yousef asked on 13 Oct 2008, 02:33 PM
string[] myArray = new string[5] {"One", "Two", "Three", "Four", "Five" };
radGridView1.DataSource = myArray; 

when doing this, why the displayed column is the length of every string?
how to display the strings themself using DataSource?
Thanks

4 Answers, 1 is accepted

Sort by
0
Rob
Top achievements
Rank 1
answered on 14 Oct 2008, 03:43 PM
Try the code bellow:

private void Form1_Load(object sender, EventArgs e)  
{  
            BindingList<CustomObject> l = new BindingList<CustomObject>();  
            l.Add(new CustomObject("one"));  
            l.Add(new CustomObject("two"));  
 
            radGridView1.DataSource = l;    
}  
 
...  
      
class CustomObject {  
        string a;  
        public CustomObject(String a){  
                this.a =a;  
            }  
 
        public string A  
        {  
              
 
            get { return a; }  
            set { a = value; }  
        }  
 

Cheers
0
Yousef
Top achievements
Rank 2
answered on 14 Oct 2008, 04:19 PM
Thanks for the reply,
this works i tried it before, but in the documentation they used the code i provided before and the display was the strings not the length.

any idea?
thanks
0
Accepted
Nick
Telerik team
answered on 15 Oct 2008, 02:19 PM
Hi Yousef,

Thank you for your question.

This behavior was changed in the current version, but the documentation still reflects the old usage. Sorry for the introduced inconvenience.

Review the following code if you need simple array binding:  

public class ValueType<T>  
{  
T item;  
 
public ValueType()  
{  
 
}  
 
public ValueType(T item)  
{  
this.item = item;  
}  
 
public T Item  
{  
get { return this.item; }  
set { this.item = value; }  
}  
}  
ArrayList list = new ArrayList();  
for (int i = 0; i < 10; i++)  
{  
list.Add(new ValueType<string>("string " + (i+1).ToString()));  
}  
 
this.radGridView1.DataSource = list;  
 


Kind regards,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Yousef
Top achievements
Rank 2
answered on 15 Oct 2008, 02:23 PM
Thanks Nick for the help.
Tags
GridView
Asked by
Yousef
Top achievements
Rank 2
Answers by
Rob
Top achievements
Rank 1
Yousef
Top achievements
Rank 2
Nick
Telerik team
Share this question
or