Serious error when hide the column

Hi,

I have one ListObject on ExcelSheet defined as:

Microsoft.Office.Tools.Excel.ListObject myListObject = this.Controls.AddListObject(this.Range["A10", missing], "myListObject");

Then I am binding this listobject as follows:

DataSet dsTrims = new DataSet();

string strWhere="select col1, col2, col3, col4 from tableTrims";

dsTrims = MyProvider.ExecuteDataSet(System.Data.CommandType.Text, strWhere);

this.bindingdataSource1.DataSource = dsTrims.Tables[0];

myListObject.AutoSetDataBoundColumnHeaders = true;

myListObject.SetDataBinding(bindingdataSource1);

Till designe time (before I started debugging), there was no column available into excelsheet/listobject. But when I run the application, all columns get appeared into listobject/excelsheet.

Now I want the column col2 and col4 should not be visible to the user i.e it should be invisible.

1. How should I make these columns invisible at run time through my code.

Thank you



Answer this question

Serious error when hide the column

  • KevinUT

    Modify your binding statement to be as follows:

    myListObject.SetDataBinding( bindingdataSource1, "", "Col1", "Col3");

    and the ListObject will only display Col1 and Col3.



  • TechCzech

    Hi,

    Thank you,

    Now I get it as working.

    Thank you


  • _ _

    Hi Tarun,

    As you suggested above code for hiding columns, I have used following code into C#, but getting error:

    Sheet2 objSheet2 = new Sheet2();

    objSheet2.Columns["A:A"]. Here I am not getting "Select" option.

    Is there any different way to create sheet objects

    Also where does I get "Selection" in C# so that I can have Selection.EntireColumn.Hidden = true.

    Thank you


  • eduboys

    Columns (G:G) is the column you want to hide. In my case it is column G. If you want to hide two columns you can do columns("G:F")

    You can find the columns you want to hide on run time (if its not known intially). Select those columns you want to hide using Columns(<columns>).select and then hide them.


  • Ratul Saikia

    Hi,

    Thanks for your reply.

    I am confused here with "Columns("G:G")", for what purpose it is used. At design time we dont know about range of the column that we want to hide. Then how can we get to know that this column will belong to G:G.

    Thank you


  • nrb1955

    I use following function in VB to hide columns

    xlOutPutSheet.Columns("G:G").Select
    Selection.EntireColumn.Hidden = True

    Where xlOutPutSheet is worksheet object.


  • Serious error when hide the column