[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Help, How make Formating of selected text in textbox

Posted on 2008-02-09
29
Medium Priority
?
237 Views
Last Modified: 2013-11-26
How to  make Formating of selected text in textbox, after saving it in database,  either while retreiving it will be formated or not.

just for clear purpose, I want to make some thing  prominent, I want to format it.
0
Comment
Question by:mahmood66
  • 14
  • 13
27 Comments
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 20857862
Textbox doesn't have anything to to persist formatting settings. You need to use RichTextbox. See http://www.emoreau.com/Entries/Articles/2003/06/Common-Dialogs.aspx
0
 

Author Comment

by:mahmood66
ID: 20860027
Can save this data of Richtextbox in database with all formating. and when we retreive this data from the database, eighter It will show the text with formatss or not. if we can store and retreive with formats  then it will be very good, i am waiting for your reply. It will be very useful for me.
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 20861205
Because you retreive the text with all the formating, if you set it to a richtextbox again, it will show correctly formatted
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:mahmood66
ID: 20909576
hmmmmmm, very good, I will check it know and let you know my dear,. if it is, it will help me alot.
0
 

Author Comment

by:mahmood66
ID: 20909670
noooooooooooo, Its data is not comming with formats, even i used ritchtextbox,

     RichTextBox1.ForeColor = Color.Blue i did, bebind color button and save it,

but when i m retretiging in richtextbox, its not coming with formatis.
Pleae check it out. if any sample u have, please send me.
0
 

Author Comment

by:mahmood66
ID: 20909684
Keep in mind, i am not storing in my file system, i m storing this data in database (Sqlserver),  i wanto to retreive from database,
1. It shold be save in my database field, with formats,
2. it shold retreive from databse field with formatis. and display in my rechtextbox.
I hope, now its more clear for you to give me answer.
i m wating wating, waitng........................
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 20909758
You probably persisted the .Text property. You need to persist the .Rtf property.

        With Me.RichTextBox1
            .Text = "this is a test"
            .ForeColor = Color.Blue
            MessageBox.Show(.Text)
            MessageBox.Show(.Rtf)
        End With
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 20909759
and BTW, you will also need to assign the RTF property when retreiving it from the database.
0
 

Author Comment

by:mahmood66
ID: 20913514
you r not telling me complete answer,  at-least u should give me exampel with database field.
Pleeessssssssssssssssss read,
again for more more clarification, U understand like this, i make small note pad. all the option i made, bold, Italic, back color, forcolor, underline, font size, then i am storing this richtextbox (formated) storing in database field (field data type is "TEXT"), so i want, when i retrive this record from databsae, it should diplay with all the formats (with which i store).
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 20914087
>>at-least u should give me exampel with database field

I don't have an example handy for this. You told me that you already have the code but it wasn't saving the formatting. What I tell you, is to use the RTF property of the RichTextbox (instead of the Text property that you are using) and it will work.
0
 

Author Comment

by:mahmood66
ID: 21059446
nooo, using RTF property, its saveing but when i i retreave back, it displays my string in differtype of tags, <b> some thing, but its not applying on text. pleasssssssssssssssssss. guide me regarding this.
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21059505
when you retreive your string, you also need to set the .RTF property (and not the .Text property)

RichTextBox1.Rtf = ValueReadFromYourDatabase
0
 

Author Comment

by:mahmood66
ID: 21060234
see screen short, i m getting this eror,

untitled.JPG
0
 

Author Comment

by:mahmood66
ID: 21060253
Please check, this error screen i m getting.
Clear-Screen-Short.JPG
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21060502
is this row containing a valid RTF content?
0
 

Author Comment

by:mahmood66
ID: 21076466
yes. but any how, please check the below code.

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ocon = New SqlConnection(gcnctstr)
        ocom = New SqlCommand
        ocon.Open()
        ocom = ocon.CreateCommand

        Dim strsql As String
        strsql = "Insert into tblDetail (Detail) values('" & RichTextBox1.Rtf & "')"
        ocom.CommandText = strsql
        ocom.Connection = ocon
        ocom.ExecuteNonQuery()

    End Sub
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21076894
are you sure that this particular row has something in this field?

you can use:

try
   RichTextBox1.Rtf = ds.tables(0).rows(0).item(0).tostring
catch ex as argumentexception
   RichTextBox1.text = ds.tables(0).rows(0).item(0).tostring    
end try

Open in new window

0
 

Author Comment

by:mahmood66
ID: 21084676
No my dear, its also not working, thakx a lot for your kind co-operation, i think i should delete this question.
but i will submit my question again with my code of saveing and retreiving,
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21084985
if you put a textbox on your form and you have this code, what do you have in your textbox:
TextBox1.text = ds.tables(0).rows(0).item(0).tostring
0
 

Author Comment

by:mahmood66
ID: 21085082
Normail string which i saved in database, i mean without formating.
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21085465
that's the problem. The database has to contains the formated string. Are you sure you are saving the RTF property. It looks like your are saving the Text property.
0
 

Author Comment

by:mahmood66
ID: 21085485
dont' worry, I will show you my code ok, then you suggest me, what to do.

0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21085492
show the code used to save to the database
0
 

Author Comment

by:mahmood66
ID: 21085504
please check it.
to save the string in RTF Format.

        ocon = New SqlConnection(gcnctstr)
        ocom = New SqlCommand
        ocon.Open()
        ocom = ocon.CreateCommand
        Try
            Dim strsql As String

            strsql = "Insert into tblDetail(Detail)values('" & RichTextBox1.Rtf & "')"

            ocom.CommandText = strsql
            ocom.Connection = ocon
            ocom.ExecuteNonQuery()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
0
 
LVL 71

Expert Comment

by:Éric Moreau
ID: 21085573
the save is good but are you sure that you always had that line.

I would suggest that you clean all the values in that field and that you restart entering data.

It will work.
0
 

Author Comment

by:mahmood66
ID: 21085585
ok, i will do it also, let see what happen's.
0
 
LVL 71

Accepted Solution

by:
Éric Moreau earned 375 total points
ID: 21775215
I really think that I have provided the solution
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses
Course of the Month7 days, 22 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question