3 Questions about spread for winform C#. Cell Click Event, Auto Column Width

Posted by: myworld7772 on 15 October 2018, 1:30 am EST

    • Post Options:
    • Link

    Posted 15 October 2018, 1:30 am EST

    Just tested out spread for winform and I like how fast it is compared to visual studio’s built in datagridview. But now I am kind of lost how I should be using this. Here are my questions.

    1. How do you fill textBox with cell click event? Below is code I used to use for datagridview. It allows to fill textBox automatically when I click the row. It seems I can’t use same code for fspread. How do I do this?
    
    if (e.Row >= 0)
                {
                    DataGridViewRow row = this.fpSpread1.[e.Row];
    
                    textBox1.Text = row.Cells["item_no"].Value.ToString();
                    textBox2.Text = row.Cells["lot_no"].Value.ToString();
                }
    
    
    1. How do you make columns fit for fspread? On datagridview, there was an option called “Fit” which will evenly distribute column width to fit the screen. It doesn’t look like fspread has this option.

    2. How do you make column width set to auto? It only gives you specific value and it will not auto width the column header.

    Thank you.

  • Posted 16 October 2018, 5:47 pm EST

    Hello,

    1>> Please use the following code to get the row value in cell click event

    
        private void fpSpread1_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
            {
                textBox1.Text = fpSpread1.ActiveSheet.Cells[e.Row, 0].Value.ToString();
    
                textBox2.Text = fpSpread1.ActiveSheet.Cells[e.Row, 1].Value.ToString();
            }
    
    

    2>> Yes, Spread does not have this functionality. You have to get the width of the sreen size and set the column width accordingly. You can refer to the following link:

    https://www.grapecity.com/en/blogs/how-to-autosize-spread-for-winforms

    3>> You can achieve the same thing by the following code:

    
     for(int i=0; i<fpSpread1.ActiveSheet.Columns.Count; i++)
                {
                    float sz = fpSpread1.ActiveSheet.Columns[i].GetPreferredWidth();
                    fpSpread1.ActiveSheet.Columns[i].Width = sz;
                }
    
    

    Hope it helps.

    Thanks,

Need extra support?

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

Learn More

Forum Channels