c# - Select whole column by clicking ColumnHeader. WPF DATAGRID -
i have data grid has disabled sorting. want achieve - clicking column header want select cells in column(select whole column). i've added eventsetter
datagridcolumnheader
bind method click
event, have no idea how method should written. ideas?
my code:
private void columnheaderclick(object sender, routedeventargs e) { var columnheader = sender datagridcolumnheader; if (columnheader != null) { if (dgdane.selectedcells != null) { dgdane.selectedcells.clear(); } foreach (var item in dgdane.items) { dgdane.selectedcells.add(new datagridcellinfo(item, columnheader.column)); } dgdane.focus(); } }
i edited code, 1 above works fine(thanks @nit). i've added focus datagrid
because necessary.
this should trick
private void columnheaderclick(object sender, routedeventargs e) { var columnheader = sender datagridcolumnheader; if (columnheader != null) { datagrid.selectedcells.clear(); foreach (var item in datagrid.items) { datagrid.selectedcells.add(new datagridcellinfo(item,columnheader.column)); } } }
make sure set selectionunit="cell"
on datagrid
<datagrid x:name="datagrid" autogeneratecolumns="false" issynchronizedwithcurrentitem="true" selectionunit="cell" />
Comments
Post a Comment