sairam

sairam

  • NA
  • 69
  • 0

RichTextBox Teasing With its behaviour- Pls help-

Jan 6 2009 3:32 PM

I have a RichTextBox called rchEditor1.

 

I have 2 Buttons called btnAdd ,btnAddImage and the list box where the names of Images are stored is called lstboximages.

 

When I press btnAddImage , an Image from DataBase is Added onto the richtextbox.

 

The Code I am Using is

 

SqlConnection cn2 = null;

            SqlCommand cmd2 = null;

            SqlDataReader reader2 = null;

 

            String gettext = "select Image from tblAddImage where ImageName = '" + lstboxImages.SelectedValue + "'";

            cn2 = new SqlConnection("User id=cmslogin;password=cmsunlock;database=CMS2;Data source=primasqltst\\qa");

            cn2.Open();

            cmd2 = new SqlCommand(gettext, cn2);

            reader2 = cmd2.ExecuteReader();

 

            while (reader2.Read())

            {

                string test = reader2[0].ToString();

                string Field2 = null;

               

 

      Field2 += rchEditor1.Rtf.Insert(rchEditor1.Rtf.Length - 4, test);

 

                rchEditor1.Rtf = Field2;

 

            }

            reader2.Close();

 

 

When I press btnAdd, a text is added onto the richtextbox.

 

The Code I am using is as follows.

 

string list = "<<" + treeContractViews.SelectedNode.Text + "." + lstboxViews.SelectedValue.ToString() + ">>";

   rchEditor1.Rtf = rchEditor1.Rtf.Insert(rchEditor1.Rtf.Length - 4, list);

 

So My Problem is listed below.

 

  1. when I press btnAddImage, The Image is getting after the last word in the richtextbox but not at the place where I place the cursor.
  2. When I press btnAdd , The Text gets added after the last word in the richtextbox but not at the place where I place the cursor.

 

So How should I place the image or text exactly at the position I desired with out disturbing other text or images.

 

Please Help Me


Answers (3)