I am working on a c# project and I am having a really weird problem.
I'm reading in a file and processing the line and storing the results in separate variables within a list array. I am then going through the list array and populating it into the datagrid.
It successfully loading the file and its a creating a new row for line in the file but each line is blank and there are no columns being displayed. Below is a screenshot of how it looks.
When I debug it I can view the contents of the variables and all the text is there as expected. Below is the code I am using
private void loadNonVerbose(List<LogCatDetails> logCatDetailsList)
{
DataSet ds = new DataSet();
DataTable table = new DataTable();
DataColumn logLevel = new DataColumn("Log Level", typeof(string));
DataColumn tag = new DataColumn("Tag", typeof(string));
DataColumn processID = new DataColumn("Process ID", typeof(int));
DataColumn message = new DataColumn("Message", typeof(string));
table.Columns.Add(logLevel);
table.Columns.Add(tag);
table.Columns.Add(processID);
table.Columns.Add(message);
ds.Tables.Add(table);
int i = 0;
foreach (LogCatDetails logCatDetails in logCatDetailsList)
{
DataRow row = table.NewRow();
row[logLevel] = logCatDetails.LogLevel.ToString();
row[tag] = logCatDetails.Tag;
row[processID] = logCatDetails.ProcessID;
row[message] = logCatDetails.Message;
table.Rows.Add(row);
if (i == 10)
{
break;
}
i++;
}
logCatDataGrid.ItemsSource = ds.Tables[0].DefaultView;
}
Thanks for any help you can provide
UPDATE Below is how the datagrid is defined in the XML
<DataGrid ColumnWidth="*" AutoGenerateColumns="False" Margin="12,51,12,12" Name="logCatDataGrid" />
row[loglevel], row[tag], row[etc]
is horrible. Also, I see you're basically wrapping thatLogCatDetails
stuff in the horrible thing. Why don't you bind the DataGrid directly to theLogCatDetailsList
?List<LogCatDetails>
.