0
votes

I have a DataTable binding to a WPF datagrid where I've created columns and created a set number of rows, with the first column populated with default values in each row. It looks like this table:

enter image description here

So I have the Size column and all its values and the headers for each column. Now I need to input the data I collected into my DataTable but not using the indexes for columns and rows, I need to find the cell item using the header titles for row and column. Here's what I have:

 heatMapTbl.Rows['2000000']['BOA'] = statVal;

Any suggestions?

2

2 Answers

0
votes

Hint:

DataTable table = new DataTable();
        var myColumn = table.Columns.Cast<DataColumn>().SingleOrDefault(col => col.ColumnName == "myColumnName");
        if (myColumn != null)
        {
            // just some roww
            var tableRow = table.AsEnumerable().First();
            var myData = tableRow.Field<string>(myColumn);
            // or if above does not work
            myData = tableRow.Field<string>(table.Columns.IndexOf(myColumn));
        }
0
votes

I looped through the rows like this:

foreach (DataRow row in LiqTbl.Rows)
                {
                    if (row.ItemArray[0].Equals(timezone))
                    {
                        foreach (DataColumn column in LiqTbl.Columns)
                        {
                            if (column.ColumnName.Equals(lp))
                            {
                                //Write the value in the corresponding row
                                row[column] = liq.ToString("N", CultureInfo.InvariantCulture);
                            }
                        }
                    }
                }