Help, How make Formating of selected text in textbox

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.
mahmood66Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
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
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
Because you retreive the text with all the formating, if you set it to a richtextbox again, it will show correctly formatted
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mahmood66Author Commented:
hmmmmmm, very good, I will check it know and let you know my dear,. if it is, it will help me alot.
0
mahmood66Author Commented:
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
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
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
Éric MoreauSenior .Net ConsultantCommented:
and BTW, you will also need to assign the RTF property when retreiving it from the database.
0
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
>>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
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
when you retreive your string, you also need to set the .RTF property (and not the .Text property)

RichTextBox1.Rtf = ValueReadFromYourDatabase
0
mahmood66Author Commented:
see screen short, i m getting this eror,

untitled.JPG
0
mahmood66Author Commented:
Please check, this error screen i m getting.
Clear-Screen-Short.JPG
0
Éric MoreauSenior .Net ConsultantCommented:
is this row containing a valid RTF content?
0
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
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
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
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
mahmood66Author Commented:
Normail string which i saved in database, i mean without formating.
0
Éric MoreauSenior .Net ConsultantCommented:
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
mahmood66Author Commented:
dont' worry, I will show you my code ok, then you suggest me, what to do.

0
Éric MoreauSenior .Net ConsultantCommented:
show the code used to save to the database
0
mahmood66Author Commented:
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
Éric MoreauSenior .Net ConsultantCommented:
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
mahmood66Author Commented:
ok, i will do it also, let see what happen's.
0
Éric MoreauSenior .Net ConsultantCommented:
I really think that I have provided the solution
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.