Skip to main content Skip to footer

Spilling Text to Adjacent Cells During Editing

With AllowMergingEnum.Spill available with C1Flexgrid long text can spill to adjacent cells. However this features works once the editing is complete. While the user is editing, text scrolls within the editor bounds. Well implementation is easier then one can think. All we need to do is handle KeyUpEdit event of C1Flexgrid, calculate the size of string while user enters text; and increase the width of editor accordingly. Following code block shows the implementation for the same.

private void c1FlexGrid1_KeyUpEdit(object sender, C1.Win.C1FlexGrid.KeyEditEventArgs e)  
    //Fetch the editor  
    TextBox tb = this.c1FlexGrid1.Editor as TextBox;  
    if (tb != null)  
      //Get handle of the textbox  
      Graphics g = Graphics.FromHwnd(tb.Handle);  
      //Fetch the space needed by text as per its FontSize/FontStyle  
      SizeF size = g.MeasureString(tb.Text, tb.Font);  
      //set width of textbox  
      tb.Width = (int)size.Width;