Hi,
Thank you for using MSDN Newsgroup! My name is Kevin, and I will be
assisting you on this issue.
First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to display an array of object
in a DataGrid and wonder what's the best way to achieve this. Please feel
free to point me out if there's any misunderstanding.
Based on my experience, I will create a DataSet, a DataTable with a column
to maintain data. The DataType property of the DataColumn will be set to
System.String. The following are .net framework types supported by
DataType. We cannot assign values other than these types to the field. If
the object array contains data other than these types, there might be some
problem when persisting and transfering data.
Boolean
Byte
Char
DateTime
Decimal
Double
Int16
Int32
Int64
SByte
Single
String
TimeSpan
UInt16
UInt32
UInt64
Here I write a short example for you. Hope this helps.
string s = "This is a string object.";
int i = 5;
DateTime dt = DateTime.Now;
object[] o = new object[]{s,i,dt};
DataSet ds = new DataSet();
ds.Tables.Add();
ds.Tables[0].Columns.Add("Column1"); //DataType will be set to String
by default.
foreach(object ob in o)
{
ds.Tables[0].Rows.Add(new object[]{ob});
}
this.dataGrid1.DataSource = ds;
For more information about DataColumn.DataType, please refer to the
following link:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemdatadatacolumnclassdatatypetopic.asp
Does this answer your question? If anything is unclear, please feel free to
reply to the post.
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."