Textbox and Texbox Cotrol getting Number of Lines in Multiline Textbox/textbox control

2 Answers 1012 Views
TextBox TextBoxControl
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Roger asked on 29 Jun 2021, 03:11 PM | edited on 30 Jun 2021, 01:01 PM

If I use a regular MS Text box I can use textbox.lines.count()  but this is invalid when using either of the Telerik textbox controls.

Is there a way to get the Number of Lines of a Textbox or TextboxControl?

Sample Code used with MS TextBox control

var lines = txtEQCodes.Lines.Count();
                lines -= String.IsNullOrWhiteSpace(txtEQCodes.Lines.Last()) ? 1 : 0;

This code does not work with Telerik textbox Controls.

I get compile errors on the Lines.Count() and Lines.Last() properties.

I am using telerik winforms.ui version 2021.2.615.40

Thanks,

 

Roger

2 Answers, 1 is accepted

Sort by
0
Arun
Top achievements
Rank 2
Iron
answered on 30 Jun 2021, 05:07 AM

HI, 

If you just wanted to get the number of lines in a multi line textbox, please try

 int _Lines = radTxtRemarks.Lines.Count;

It's working for me.

Roger
Top achievements
Rank 2
Iron
Iron
Iron
commented on 30 Jun 2021, 12:58 PM | edited

Count is not an option for me, as it is a compile error on my RadTextBox (Version 2021.2.615.40) This is a Winform application running in .Net Framework 4.6.1
Arun
Top achievements
Rank 2
Iron
commented on 30 Jun 2021, 01:32 PM

I am using VB.Net (VS2017) & RadTextBox (Version: 2017.3.1017.40), It's working for me.
0
Nadya | Tech Support Engineer
Telerik team
answered on 30 Jun 2021, 03:32 PM

Hello, Roger,

I have tested the RadTextBox.Lines.Count() and RadTextBox.Lines.Last() methods with the latest Telerik version and they both are working as expected on my side. I also added a standard MS TextBox to compare the results to RadTextBox and would like to note that they behave the same way. Please refer to the following code snippet. I have also attached my test project so you can give it a try.

 public RadForm1()
 {
     InitializeComponent();
     this.radTextBox1.Text = "Hello" + "\r\n" + "I am RadTextBox" + "\r\n" + "Multiline = true";
     this.textBox1.Text = "Hello" + "\r\n" + "I am MS TextBox" + "\r\n" + "Multiline = true";
 }

 private void radButton1_Click(object sender, EventArgs e)
 {
     var count = this.radTextBox1.Lines.Count();
     var count2 = this.textBox1.Lines.Count();

     //TextBox
     var lines = textBox1.Lines.Count();
     lines -= String.IsNullOrWhiteSpace(textBox1.Lines.Last()) ? 1 : 0;

     //RadTextBox
     var radlines = radTextBox1.Lines.Count();
     radlines -= String.IsNullOrWhiteSpace(radTextBox1.Lines.Last()) ? 1 : 0;
 }

@Arun,  Thank you for your suggestions.

I hope this helps. Should you have further questions do not hesitate to ask.

Regards,
Nadya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
TextBox TextBoxControl
Asked by
Roger
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Arun
Top achievements
Rank 2
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or