C# 如何在PrintPreview窗口中隐藏dx:GridControl的一列?

C# 如何在PrintPreview窗口中隐藏dx:GridControl的一列?,c#,wpf,devexpress,C#,Wpf,Devexpress,我有一个包含许多列的DevExpress GridControl。现在在打印/导出期间,我想隐藏一列。逻辑是什么?我如何才能做到这一点?在单击事件中,您可以隐藏列 每个GridView列都具有可见和可见索引属性。您只需关闭Visible属性以隐藏列,然后再打开它以再次显示。如果将此属性设置为-1,则列也将隐藏 void HideColumn(object sender, EventArgs e) { colToHide.Visible=false; } PrintPr

我有一个包含许多列的DevExpress GridControl。现在在打印/导出期间,我想隐藏一列。逻辑是什么?我如何才能做到这一点?

在单击事件中,您可以隐藏列

每个
GridView
列都具有
可见和可见索引
属性。您只需关闭Visible属性以隐藏列,然后再打开它以再次显示。如果将此属性设置为
-1
,则列也将隐藏

void HideColumn(object sender, EventArgs e)
{
    colToHide.Visible=false;         
}
PrintPreview显示与源网格相同的列。要显示的列是在生成文档时获取的。调用
VisualDataNodeLink
CreateDocument方法时,可以通过将Visible设置为false来隐藏所需的列

有关更多信息,请参阅此链接

受保护的void printalpages(对象发送者,事件参数e)
{
GridView1.AllowPaging=false;
GridView1.DataBind();
GridView1.HeaderRow.Cells[9].Visible=false;
GridView1.FooterRow.Cells[9].Visible=false;
//循环行并隐藏第一列中的单元格
对于(int i=0;i
protected void PrintAllPages(object sender, EventArgs e)
    {
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.HeaderRow.Cells[9].Visible = false;
        GridView1.FooterRow.Cells[9].Visible = false;
        // Loop through the rows and hide the cell in the first column
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];
            row.Cells[9].Visible = false;
        }
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        hw.AddStyleAttribute(HtmlTextWriterStyle.Direction, "rtl");
        GridView1.RenderControl(hw);
        string gridHTML = sw.ToString().Replace("\"", "'")
            .Replace(System.Environment.NewLine, "");
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type = 'text/javascript'>");
        sb.Append("window.onload = new function(){");
        sb.Append("var printWin = window.open('', '', 'left=0");
        sb.Append(",top=0,width=1000,height=600,status=0');");
        sb.Append("printWin.document.write(\"");
        sb.Append(gridHTML);
        sb.Append("\");");
        sb.Append("printWin.document.close();");
        sb.Append("printWin.focus();");
        sb.Append("printWin.print();");
        sb.Append("printWin.close();};");
        sb.Append("</script>");
        ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
        GridView1.AllowPaging = true;
        GridView1.DataBind();
    }
    protected void PrintCurrentPage(object sender, EventArgs e)
    {

        GridView1.PagerSettings.Visible = false;
        GridView1.DataBind();
        GridView1.HeaderRow.Cells[9].Visible = false;
        GridView1.FooterRow.Cells[9].Visible = false;
        // Loop through the rows and hide the cell in the first column
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];
            row.Cells[9].Visible = false;
        }
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        hw.AddStyleAttribute(HtmlTextWriterStyle.Direction, "rtl");
        GridView1.RenderControl(hw);            
        string gridHTML = sw.ToString().Replace("\"", "'")
            .Replace(System.Environment.NewLine, "");
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type = 'text/javascript'>");            
        sb.Append("window.onload = new function(){");
        sb.Append("var printWin = window.open('', '', 'left=0");
        sb.Append(",top=0,width=1000,height=600,status=0');");
        sb.Append("printWin.document.write(\"");
        sb.Append(gridHTML);
        sb.Append("\");");
        sb.Append("printWin.document.close();");
        sb.Append("printWin.focus();");
        sb.Append("printWin.print();");
        sb.Append("printWin.close();};");
        sb.Append("</script>");
        ClientScript.RegisterStartupScript(this.GetType(), "GridPrint", sb.ToString());
        GridView1.PagerSettings.Visible = true;
        GridView1.DataBind();
    }