Custom columns with images

Posted by: vjoy on 8 September 2017, 2:50 pm EST

  • Posted 8 September 2017, 2:50 pm EST

    Hi,

    I want to add my own columns with image in each cell except header cell. How to go with it ?

    I am using a bindingsource control to populate data to the grid. I also want specific columns from the underlying table and not all the columns.

    Is there any way to hide columns based on their header text ? Tag property is giving me a Null reference exception.

  • Replied 8 September 2017, 2:50 pm EST

    Thanks for the reply. Now I am able to customize the columns as per the requirements. In the attached example, image is assigned to a particular cell.

    If I want to assign the same image for the entire column, is there any other alternative like DataGridView control ?

  • Replied 8 September 2017, 2:50 pm EST

    Hello,

    You can the cell type of each cell in a column to ImageCellType and then assign the same image to each cell in the column and this would populate the complete column with the same image.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:50 pm EST

    Hello,

    Once you have set the datasource of Spread, you can add your own columns later simply by increasing the ColumnCount of the sheet. You can refer to the following link for further clarification:

                                             http://www.clubfarpoint.com/FarPointSupportSite/Modules/Docs/SpreadWin5Help/spwin-databind-unboundcol.html

    Later, when you want to have images in all the cells, then you would need to set the celltype of each cell to ImageCellType and assign an image to each cell, this link would help you with the same:

                                           http://www.clubfarpoint.com/FarPointSupportSite/Modules/Docs/SpreadWin5Help/spwin-setimagecell.html.

    I would like you to know that you can bind the Spread with specific columns of the table, you need not hide the columns if you do not want them to be there in the bound Spread. This link would guide you ahead with the same:

                                          http://www.clubfarpoint.com/FarPointSupportSite/Modules/Docs/SpreadWin5Help/spwin-databind-field.html

    Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Subodh Sinha.

     

  • Replied 8 September 2017, 2:50 pm EST

    Thanks for the help. These links resolved some of my issues.

    What I am trying to do is, I have one table with 20 columns. I want to display few of them to the user. I also have some custom columns which are not being populated from database table.

    It will be really helpful if you could guide me in this direction.

    Thanks once again.

  • Replied 8 September 2017, 2:50 pm EST

    Hello,

    I would like you to know that you can hide some of the columns from the user either by binding specific columns with Spread which you want the user to see, the same is explained in the link mentioned in the previous post. Later if  you want you can add the custom columns by increasing the
    ColumnCount of the sheet and then assign a value to each cell, to
    populate those columns.

    However, if you want to bind Spread with complete table and later hide some of the columns then you can make use of the Label property of the column. The piece of code for the same would be:

                                                                           if(fpSpread1.Sheets[0].Columns[ 0].Label == "Name")

                                                                                  fpSpread1.Sheets[0].Columns[0].Visible = false;

    And once again increase the ColumnCount to add custom columns and populate them with values.

    I have attached a sample that depicts these scenarios. Kindly have a look at it. Hope it will help you. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur.


    2011/12/DataBind.zip
  • Replied 8 September 2017, 2:50 pm EST

    Can you please provide code/property to do this ? This is a custom column. Do I need to iterate over all the cells ?
  • Replied 8 September 2017, 2:50 pm EST

    Hello,


    Here is the code to implement the same:


    private void Form1_Load(object sender, EventArgs e)


    {


          //Setting the row count.


          fpSpread1.Sheets[0].RowCount = 10;


               


          //Defining ImageCellType


          FarPoint.Win.Spread.CellType.ImageCellType imgct = new FarPoint.Win.Spread.CellType.ImageCellType();


          System.Drawing.Image image = System.Drawing.Image.FromFile(@"C:\Documents and Settings\Administrator\Desktop\image1.gif";


              


          //Setting the celltype for the column.


          fpSpread1.Sheets[0].Columns[1, 1].CellType = imgct;


               


          //Setting the same image for all the cells in a column.


            for(int r=0; r


                fpSpread1.Sheets[0].Cells[r, 1].Value = image;


    }


     


    Hope it will help you. Please let me know if you have any queries further.


     


    Thanks,


    Manpreet Kaur.

  • Replied 8 September 2017, 2:50 pm EST

    Iterating through all the cells of a column was my last option. I was thinking of some sort of property to achieve this.

    Thanks for your help. Smile

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels