i have created wpf application loads 2 datagrids data sqlclient datatables. have method below compares 2 tables. working fine, must have changed in code broke it. datagridrow1 , datagridrow2 variables null. how can datagridrow datarowview?
private void comparedatatables(string primarykey) { foreach (datarowview datarowview1 in datagrid1.itemssource) { datagridrow datagridrow1 = datagrid1.itemcontainergenerator.containerfromitem(datarowview1) datagridrow; if (datagridrow1 != null) { int primarykeyvalue1 = (int)datarowview1.row[primarykey]; foreach (datarowview datarowview2 in datagrid2.itemssource) { //datarowview datarowview2 = (datarowview)datagridrow2.item; int primarykeyvalue2 = (int)datarowview2.row[primarykey]; if (primarykeyvalue1 == primarykeyvalue2) { foreach (datagridcolumn column in datagrid1.columns) { datagridrow datagridrow2 = datagrid2.itemcontainergenerator.containerfromitem(datarowview2) datagridrow; if (datagridrow2 != null) { frameworkelement frameworkelement1 = column.getcellcontent(datagridrow1); frameworkelement frameworkelement2 = getframeworkelement(datagrid2, datagridrow2, (string)column.header); if (frameworkelement1 textblock && frameworkelement2 textblock) { textblock textblock1 = frameworkelement1 textblock; textblock textblock2 = frameworkelement2 textblock; if (textblock1.text != textblock2.text) { textblock1.background = brushes.lightsalmon; textblock2.background = brushes.lightsalmon; } } } } break; } } } } }
instead of grid.itemcontainergenerator.containerfromitem, please use grid.itemcontainergenerator.containerfromindex function, because datadrid using virtulization item not generated @ time.
Comments
Post a Comment