c# - wpf datagrid filling data -
there problem fill datagrid dynamic source. example, want fill datagrid objects has various parameters. parameters display dynamic info database. columns count may changed , parameters count may changed counts equals. fill headers:
private void datasoursechanged(sourcelist sourcelist) { columns.clear(); columns.add(new datagridtextcolumn()); if (sourcelist != null) { foreach (var item in sourcelist.columnsheaders) columns.add(new datagridtextcolumn { header = item }); } } public class sourcelist { private readonly ilist _columnsheaders; private readonly ilist _rowsheaders; private readonly ilist _datarows; public ilist columnsheaders { { homecoming _columnsheaders; } } public ilist rowsheaders { { homecoming _rowsheaders; } } public ilist datarows { { homecoming _datarows; } } public sourcelist(ilist rowsheaders, ilist columnsheaders, ilist datarows) { _rowsheaders = rowsheaders; _columnsheaders = columnsheaders; _datarows = datarows; } }
i want fill headers , rows (rows merge of _rowsheaders[i] in first column , other columns _datarows[i]) rows fills objects has properties. may fill datagrid dynamic length?
there not solutions create custom grid derives system.windows.controls.grid , create custom logic fill grid
public static readonly dependencyproperty customsourceproperty = dependencyproperty.register( "customsource", typeof(sourcelist), typeof(interactivegrid), new frameworkpropertymetadata(null, frameworkpropertymetadataoptions.bindstwowaybydefault, customsourcechanged ) ); [category("group properties")] public sourcelist customsource { { homecoming (sourcelist)getvalue(customsourceproperty); } set { setvalue(customsourceproperty, value); } } private void customsourcechanged(sourcelist sourcelist) { //... } private static void customsourcechanged(dependencyobject d, dependencypropertychangedeventargs e) { ((interactivegrid)d).customsourcechanged((sourcelist)e.newvalue); }
c# wpf datagrid
No comments:
Post a Comment