Reputation: 6337
I have some values in a DataGridRow
(item Array) and I want to fetch all these values into a string array. How can I achieve this?
DataGridRow row = (DataGridRow)Lst.ItemContainerGenerator.ContainerFromIndex(k);
DataRowView Drv = (DataRowView)row.Item;
DataRow dr = (DataRow)Drv.Row;
Upvotes: 17
Views: 80126
Reputation: 2073
This one worked for me:
string[] months = string.Join(",", dataTable.Rows[0].ItemArray).Split(',').ToArray();
Upvotes: 1
Reputation: 36300
var rowAsString = string.Join(", ", dr.ItemArray.Select(c => c.ToString()).ToArray());
This should give you a string with each item in your data row separated by a comma.
Upvotes: 7
Reputation: 747
LINQ adds some sugar:
var stringArray = dr.ItemArray.Cast<string>().ToArray()
Upvotes: 10
Reputation: 321
var rowAsString = string.Join(", ", dataTable.Rows[0].ItemArray);
No need of any lambda expresion as above.
Upvotes: 32
Reputation: 60694
One possibility is to call dr.ItemArray;
This will get you a object[]
. Then you have to cast each object to string
before you use it.
Upvotes: 17