Problem in Binding datagrid control to Arraylist
-
Hi, I am binding my DataGrid control to an arrayList that contains strings as datagrid1.datasource = str where str is the ArrayList. On executing the code, the datagrid displays the length of the strings instead of the strings themseleves. How do i make the datagrid display the strings contained in the arraylist and not the length. Thanks!
-
Hi, I am binding my DataGrid control to an arrayList that contains strings as datagrid1.datasource = str where str is the ArrayList. On executing the code, the datagrid displays the length of the strings instead of the strings themseleves. How do i make the datagrid display the strings contained in the arraylist and not the length. Thanks!
This is actually by design that this happens. An array doesn't implement the databinding interfaces, so the DGV looks at the only property that it can find on each element, Length. You'd have to expose the array in a wrapper class that exposes the text of the string as a property. You cannot bind to the string text without it being exposed by a property.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
This is actually by design that this happens. An array doesn't implement the databinding interfaces, so the DGV looks at the only property that it can find on each element, Length. You'd have to expose the array in a wrapper class that exposes the text of the string as a property. You cannot bind to the string text without it being exposed by a property.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007