C1PrintDocument is ideally used for displaying the generated Reports. However, it goes beyond this feature and supports user interactivity as it can act as a container for few input controls like TextBox, Button, CheckBoxes and RadioButtons. Along with support for these input controls, C1PrintDocument also has the has the capability of validating the Input actions. This blog explains an approach to validate the text in RenderInputText object wherein we will use C1PrintDocument's InputTextChanged event for the validation. First of all add a couple of RenderObjects like RenderText, RenderInputText on different pages of C1PrintDocument.


//RenderObjects on page 1  
rt = new RenderText("Document for Validating Render Input Text" + System.Environment.NewLine, new Font("Verdana", 14, FontStyle.Bold), Color.Red, AlignHorzEnum.Center);  
doc.Body.Children.Add(rt);  
ro = new C1.C1Preview.RenderText("Enter text of length 7");  
ro.Width = "5cm";  
ro.Y = "1in";  
doc.Body.Children.Add(ro);  
rit1 = new C1.C1Preview.RenderInputText();  
rit1.Name = "First RIT";  
rit1.Y = "prev.bottom + 0.10in";  
rit1.Width = "5cm";  
doc.Body.Children.Add(rit1);  

For validating the input controls, we will use C1PrintDocument's InputValueChanged event for validating the text in RenderObjects.


void doc_InputValueChanged(C1PrintDocument sender, InputValueChangedEventArgs e)  
{  
    if (valid == false)  
    {  
       valid = true;  

       if (e.RenderObject.GetType() == typeof(RenderInputText))  
       {  
          if ((e.RenderObject.Name == rit1.Name) && (e.RenderObject as C1.C1Preview.RenderInputText).Text.Length >7)  
          {  
              string txt = (e.RenderObject as C1.C1Preview.RenderInputText).Text;  
              MessageBox.Show("Clipping text greater than 7", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
              rit1.Text = txt.Substring(0, 7); // Clip the text after 7 characters  
              doc.Generate();  
          }  
          else if ((e.RenderObject.Name == rit2.Name) && (e.RenderObject as C1.C1Preview.RenderInputText).Text.Length > 5)  
          {  
              string txt = (e.RenderObject as C1.C1Preview.RenderInputText).Text;  
              MessageBox.Show("Clipping text greater than 5", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
              rit2.Text = txt.Substring(0, 5);  
              doc.Generate();  
          }  
          else if ((e.RenderObject.Name == rit3.Name) && (e.RenderObject as C1.C1Preview.RenderInputText).Text.Length > 3)  
          {  
              string txt = (e.RenderObject as C1.C1Preview.RenderInputText).Text;  
              MessageBox.Show("Clipping text greater than 3", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);  
              rit3.Text = txt.Substring(0, 3);  
              doc.Generate();  
          }  
       }  
    }  
    else  
      valid = false;  
}  

This brings to the end of the blog implementation. Similarly, you can further try various kind of validations in RenderObjects. Download the samples for complete implementation.