.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Removing first line/getting TextRange from TextBox

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :WPF


I have a plain TextBox and I need to remove the first line in it. Better than setting the Text property with whole new content I thought I would get a TextRange containing the first line and set its Text to empty string, but I cannot figure out how to get TextPointers from the TextBox.

Any idea how to get it or other way to do it?


View Complete Post

More Related Resource Links

Is textbox the only control with a multi-line option?

I was trying to use a label control to print out a string with spaces and line feeds, but with no success. Textbox is the only control I have found so far that will print my line feeds (ControlChars.Lf)  However, can I remove the scrollbar from the textbox display that appears when textboxmode is set to multiline? -smc

Reading MultiLine TextBox line by line

If I have a list of something in a MultiLine TextBox, one item per line, how do I then in turn read this? Right now TextBox.Text reads it all as one line. Lets say we have this: TextBox txtbx; At first I thought I could split the string on Environment.Newline, this doesn't work.  Error.Next I thought I could Replace(Environment.Newline,";").Split(";"); This didn't work either, Error.  Both gave cannot convert string to char[] exceptions. What I want to be able to do is read the input line by line and do something with each item one by one. Does anyone know how to do this?Thanks.

Read a multilined textBox line by line

Hi, I am trying to read a multilined textBox line by line into a List<String> but with the code below the compiler says that "'System.Environment' does not contain a definition for 'Newline' String getLine = ""; List<String> getLines = new List<String>(); string[] mylines = TextBox6.Text.Split(Environment.Newline); for (int i = 0; i < mylines.Length; i++) { getLine = mylines[i].ToString(); getLines.Add(getLine); }  

How Do I display only the last line of a Multiline TextBox when rows=1?


hi all,

This is the current code I am using:

                      <asp:TextBox ID="txtBoxComments" runat="server" MaxLength="5000" ReadOnly="true" Rows="1" Text='<%# Eval("Comments") %>'
                       TextMode="MultiLine" Width="100%" Wrap="true" />

 Thank you!


Trying to display only the last line of a Multiline TextBox


Hi all,

On my Asp.Net GridView I am binding a textbox to a field in SQL. Sometimes the content of the textbox is more than 1 line and I
need to show only the LAST line. How can I do that? Here is part of my code...notice that I use Rows=1 on purpose so that
I am able to show only 1 line but I need it to scroll all the way down and have it show only the last line of the whole content:

  <asp:TextBox ID="txtBoxComments" runat="server" MaxLength="5000" ReadOnly="true" Rows="1" Text='<%# Eval("Comments") %>'
      TextMode="MultiLine" Width="100%" Wrap="true" />

 Thank you!

regarding display textbox and image in same line using ajax ...


iam uing ajax to check availblity of username from sql. evrythng is working fine ...only the thing is the image i want to dispaly aftr the text using:http://encosia.com/2007/07/02/aspnet-username-availability-checking-via-ajax/ but how to display images aftr the text box...it displays in next line ..please can u help me ..how to display images next to texbox...

How to input line breaks and formating in textbox with multilines ?


I have a web form in which anyone can fill out the information and i recieve the information.

<asp:TextBox ID="Body" runat="server" Columns="55" Height="101px" Rows="30" TextMode="MultiLine"

The problem is while entering the information in this text box, if anyone used enter line or different line or any kind of formatting, as a result i don't get the formatted page or with lines. I see only a paragraph which is very difficult to read and understand.

How to make my textbox compatible with all kind of formatting options so that even if someone paste information from word etc in the text box , i should get the formatter information just like the user pasted the information in the text box...

How do I make it so when I user pressing return, it goes to the next line in a textbox?

I've got a textbox control on a WPF 4.0 app I've written.  This control allows for multiple lines, and that works fine.  However, my users like to be able to type something, hit the enter/return key which they're used to having it go to the next line in the textbox, where they then continue typing whatever it is they want to type.  Well, it's not doing that.  How do I make it do that?

Removing blank line from a text file


Hi i have a comma deliminated text file which i am using to generate a multidimensional array using the following code:

Dim DefinitiveDatabase As String(,)
    Dim strfilename As String = (Server.MapPath("~\Definitive database.txt"))
    Dim num_rows As Long
    Dim num_cols As Long
    Dim x As Integer
    Dim y As Integer
    Dim value As Integer
    Dim ConditionName As String
    Dim strlines() As String
    Dim strline() As String
    Dim tmpstream As StreamReader = File.OpenText(strfilename)

strlines = tmpstream.ReadToEnd().Split(Environment.NewLine)
        num_rows = UBound(strlines)
        strline = strlines(0).Split(",")
        num_cols = UBound(strline)
        ReDim DefinitiveDatabase(num_rows, num_cols)
        For x = 0 To num_rows
            strline = strlines(x).Split(",")
            For y = 0 To num_col

How can I stop CR from being removed when a multi-line textbox in a section is within another sectio



I have a multi-line text box that sits in an optional section. This optional section is within another optional section. When it is displayed it has CR removed. I know that it does work when there is only one encompassing section.

Does anyone know how to stop this happening? Any clever little tricks...;)

Actually - just tested again and I can get it to work sometimes i.e. when I first open the form, but then it will remove CR from the mentioned section when another optional section is opened - any ideas???? 



Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Highlighting Rows with TextBox OnFocus

In another article I explained that how you can make the rows of the GridView control clickable and highlight them when they are clicked. In this article I will explain that how you can highlight the GridView rows when you focus on the TextBox which is contained inside the GridView control.

Custom Editing Behavior for DataGridView TextBox Columns

For various reasons I'm using a DataGridView instead of a ListView, and while configuring the DataGridView to look like a ListView wasn't much of a problem, there's one thing that got on my nerves, which is the behavior of textbox cells in edit mode: It is much too easy to leave the edit mode accidentally, simply by pressing the cursor keys at the wrong time. For example when the text caret is positioned behind the last character of the textbox cell content, and you press the right arrow key

Editable Gridview with Textbox, CheckBox, Radio Button and DropDown List

This is an example of an editable gridview containing different ASP.NET controls. When user wants to edit values in gridview, she/he can use these controls to edit existing values in Gridview Edit Mode.

Using the Code

watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

How to take value of bound field of grid in a variable or in a textbox.


How to take value of bound field of grid in a variable or in a textbox.

 I m using this code in .aspx page for grid.

<asp:GridView ID="Grd_Mprocess" runat="server" AutoGenerateColumns="False"

                      Width="100%" AllowPaging="True"


                      AllowSorting="True" PageSize="5"  >

                 <RowStyle CssClass="odd" />


<asp:BoundField HeaderText="DOC_TYPE_PK" DataField="DOC_TYPE_PK"  Visible="true" >


  <asp:TemplateField HeaderText="DOC TYPE ID" Visible="true">  &nbs

Textbox in ItemTemplate inside Gridview, unable to get the value


Hi. I have a itemtemplate inside a gridview.

<asp:TemplateField HeaderText="Enter OTP">
                            <asp:Label ID="Label2" runat="server"
                                style="font-family: Arial, Helvetica, sans-serif; font-size: x-small"
                                Text="PIN Num:"></asp:Label>
                            &nbsp;<asp:TextBox ID="txtPIN" runat="server" Height="21px" Width="100px"></asp:TextBox>

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend