c# - Sorting DataTable string column, but with null/empty at the bottom -
i need sort datatable or datagridview column string value, null/empty values @ bottom when sorting ascending.
the datatable not populated sql statement, no order by.
if do
datagridview1.sort(new rowcomparer(system.componentmodel.listsortdirection.ascending))
then throws exception, saying datagridview databound, correct, doesn't me, , want keep databound.
it's .net 2.0, means no linq available!
in cases if have column in table:
select completed, completed null isnull table order isnull desc, completed desc
edit:
in vb.net
each srsearchresult in srcsearchresultcollection try dr = dt.newrow() dr("cn") = srsearchresult.getdirectoryentry().properties("cn").value dr("account") = srsearchresult.getdirectoryentry().properties("samaccountname").value dr("nachname") = srsearchresult.getdirectoryentry().properties("sn").value dr("vorname") = srsearchresult.getdirectoryentry().properties("givenname").value dr("mail") = srsearchresult.getdirectoryentry().properties("mail").value dr("homedirectory") = srsearchresult.getdirectoryentry().properties("homedirectory").value dr("logonscript") = srsearchresult.getdirectoryentry().properties("scriptpath").value dr("isnull") = string.isnullorempty(dr("nachname").tostring()) dt.rows.add(dr) catch ex exception end try next srsearchresult dt.defaultview.sort = "isnull asc, nachname asc"
Comments
Post a Comment