Databinding with string[]

  • Thread starter Thread starter codymanix
  • Start date Start date
C

codymanix

How can I bind a string-Array to a DataGrid? I've already set the
MappingName in the to DataGridTablestyle to "Array", but the Grid seems to
display only Garbage:

Lenght|
-------|
13
9
3
3
3

What is this? I didn't name a Column "Lenght", neither includes the array
numbers.
The contents of the array looks like this:
string[]{"a","b","c","d","e","f"}.
 
codymanix said:
How can I bind a string-Array to a DataGrid? I've already set the
MappingName in the to DataGridTablestyle to "Array", but the Grid seems to
display only Garbage:

Lenght|
-------|
13
9
3
3
3

What is this? I didn't name a Column "Lenght", neither includes the array
numbers.
The contents of the array looks like this:
string[]{"a","b","c","d","e","f"}.

For a simple array the data grid will show all available properties.
The only available property on string is "Length", i.e. the strings length.

this will show the string:

public class Letter {
private string name_;

public Letter( string name ){
name_ = name;
}
public string Name {
get { return name_; }
}
public int Length {
get { return name_.Length; }
}
}

private string[] stringArray_ = {"a","b","c","d","e","f"};
private Letter[] letterArray_ = null;

public Form1() {
InitializeComponent();

letterArray_ = new Letter[stringArray_.Length];
for( int i = 0; i < stringArray_.Length; ++i )
letterArray_ = new Letter( stringArray_);

dataGrid.DataSource = letterArray_;
}

To control the properties that are shown for an Array or ArrayList
you have to employ TableStyles; see

George Shepherd's Windows Forms FAQ
4.7 How can I bind an ArrayList to a DataGrid
http://www.syncfusion.com/faq/winforms/search/818.asp
 
Back
Top