Add HyperLinkButton Column In Grid
hello everyone,
i have 1 datagrid auto generated column true , have column dynamatically in end of column have 1 image within hyperlinkbutton , have click event of hyperlinkbutton.
i tried
var mytemplatecolumn = new datagridtemplatecolumn(); mytemplatecolumn.header = "view"; mytemplatecolumn.celltemplate = (datatemplate)xamlreader.load("<datatemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><hyperlinkbutton navigateuri=\"\" x:name=\"hlink_btnview\"><image source=\"http://localhost:37947/images/icon-pencil.png\"/></hyperlinkbutton></datatemplate>"); accountinggrid.columns.add(mytemplatecolumn);
private void mygrid_loadingrow(object sender, datagridroweventargs e) { datagridrow datarow = e.row; foreach (datagridcolumn datacol in mygrid.columns) { frameworkelement cellcontent = datacol.getcellcontent(e.row); hyperlinkbutton linkbutton = cellcontent.findname("hlink_btnview") hyperlinkbutton; if (linkbutton != null) { linkbutton.click -= view_click; linkbutton.click += new routedeventhandler(view_click); } } }
private void view_click(object sender, routedeventargs e)
{
}
it gives error.even tried just
var mytemplatecolumn = new datagridtemplatecolumn(); mytemplatecolumn.header = "view"; mytemplatecolumn.celltemplate = (datatemplate)xamlreader.load("<datatemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><hyperlinkbutton navigateuri=\"\" x:name=\"hlink_btnview\"><image source=\"http://localhost:37947/images/icon-pencil.png\"/></hyperlinkbutton></datatemplate>"); accountinggrid.columns.add(mytemplatecolumn);
but dynamatically added column not load , if remove x:name=\"hlink_btnview\" load.
i tried
<usercontrol.resources>
<datatemplate x:name="viewdatatemplate">
<hyperlinkbutton x:name="hlinkbtn_view" >
<image resources="http://localhost:37947/images/icon-pencil.png"></image>
</hyperlinkbutton>
</datatemplate>
</usercontrol.resources>
var templatecolumn = new datagridtemplatecolumn();
templatecolumn.header = "view";
templatecolumn.celltemplate = (datatemplate)resources["viewdatatemplate"];
mygrid.columns.add(templatecolumn);
but same issue cant add dynamatically add column click event in end of column
thanks in advance.
hi hiren.shah
you there. there exists small defect in code.when adding datatemplate dynamically, need add definition of x namespace below:
var mytemplatecolumn = new datagridtemplatecolumn(); mytemplatecolumn.header = "view"; mytemplatecolumn.celltemplate = (datatemplate)xamlreader.load("<datatemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"><hyperlinkbutton navigateuri=\"\" x:name=\"hlink_btnview\"><image source=\"images/100.jpg\"/></hyperlinkbutton></datatemplate>"); datagrid1.columns.add(mytemplatecolumn);
best regards
Silverlight > Getting Started with Silverlight
Comments
Post a Comment