Reputation: 4240
I have number of string arrays. For example an array of 13 usernames then a seperate array of 13 passwords. Could someone please tell me what the most efficient way of getting these into a WFP datagrid is?
The simple option I can think of is to loop through the arrays, pick out the values and add them as a row into the datagrid but I was wondering if I can pass the arrays in as columns or something?
Please let me know if you need anymore information.
Upvotes: 0
Views: 500
Reputation: 19895
DataGrid works on attributes (columns) and items (rows) concept. So datastructures like collection of objects, data table or XML works best for loading data ibnto DataGrid
intuitively.
With arrays of plain value types, you would have to convert them into a data structure. Use linq for your advantage...
var consolidatedList =
arrayUserName.Select(
usrNm =>
new {
UserName = usrName,
Password = arrayPasswords[arrayUserName.IndexOf(usrName)]
}).ToList();
dataGrid.ItemsSource = consolidatedList;
Of couse the list generation would be slow for large number of items in the arrays. In such case run a loop or use PLINQ (in case of .Net 4.0).
Upvotes: 1