Click here to Skip to main content
15,896,063 members
Home / Discussions / C#
   

C#

 
GeneralRe: add reference for Microsoft.Office.Core dll Pin
A Khan2-May-05 23:11
sussA Khan2-May-05 23:11 
GeneralRe: add reference for Microsoft.Office.Core dll Pin
ankur.sharma.2358-Aug-16 23:56
ankur.sharma.2358-Aug-16 23:56 
Generalcombobox and auto-completion Pin
gibono2-May-05 22:39
gibono2-May-05 22:39 
GeneralRe: combobox and auto-completion Pin
Dan_P2-May-05 22:54
Dan_P2-May-05 22:54 
GeneralRe: combobox and auto-completion Pin
Anonymous2-May-05 23:42
Anonymous2-May-05 23:42 
GeneralRe: combobox and auto-completion Pin
jklucker3-May-05 7:19
jklucker3-May-05 7:19 
GeneralRe: combobox and auto-completion Pin
gibono8-May-05 23:22
gibono8-May-05 23:22 
Questionhow to bind a richtextbox control's rtf property to the database?? Pin
2-May-05 21:04
suss2-May-05 21:04 
how to bind a richtextbox control's rtf property to the database??
I convert it to byte array and pass it on in a stream as a byte array and then call
Loadfile method of RichTextBox and pass the stream.
but it says that the specified file is not in a correct format
can u please suggest

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
namespace deleteit1
{
public class richtextbox : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox2;
private deleteit1.Dataset1 dataset11;
private System.Windows.Forms.ComboBox comboBox1;
private System.ComponentModel.IContainer components;

public richtextbox()
{
InitializeComponent();
}
[STAThread]
static void Main()
{
Application.Run(new richtextbox());
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.richTextBox2 = new System.Windows.Forms.RichTextBox();
this.dataset11 = new deleteit1.Dataset1();
this.comboBox1 = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.dataset11)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(552, 368);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox2
//
this.richTextBox2.Location = new System.Drawing.Point(16, 8);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.Size = new System.Drawing.Size(624, 336);
this.richTextBox2.TabIndex = 2;
this.richTextBox2.Text = "richTextBox2";
this.richTextBox2.TextChanged += new System.EventHandler(this.richTextBox2_TextChanged);
//
// dataset11
//
this.dataset11.DataSetName = "Dataset1";
this.dataset11.Locale = new System.Globalization.CultureInfo("en-US");
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(32, 368);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(320, 21);
this.comboBox1.Sorted = true;
this.comboBox1.TabIndex = 3;
this.comboBox1.Text = "comboBox1";
//
// richtextbox
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 430);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.richTextBox2);
this.Controls.Add(this.button1);
this.Name = "richtextbox";
this.Text = "richtextbox";
this.Load += new System.EventHandler(this.richtextbox_Load);
((System.ComponentModel.ISupportInitialize)(this.dataset11)).EndInit();
this.ResumeLayout(false);

}
#endregion

SqlConnection con = new SqlConnection();
private void richtextbox_Load(object sender, System.EventArgs e)
{
con.ConnectionString = @"data source = DEVELOPMENT;user id = SHC;password = SHC;initial catalog = SHC";
if(con.State == 0)
{
con.Open();
}
try
{
string st;
st = "select * from deleteit";
SqlDataAdapter ad = new SqlDataAdapter(st,con);
ad.Fill(dataset11,0,0,"deleteit");

char[] chardata = new char[1000];
DataTable dt = dataset11.Tables[0];
ArrayList arr = new ArrayList();
//byte[] binaryData = new byte[1000];
//Encoder e1 = Encoding.UTF8.GetEncoder();
Encoding encode = Encoding.UTF8;
if(dt.Rows.Count>0)
{
foreach(DataRow row in dt.Rows)
{
// Convert the string into a byte[].
byte[] binaryData = encode.GetBytes(row["rtf"].ToString());
comboBox1.Items.Add(row["rtf"]);
comboBox1.SelectedIndex = 0;
//MessageBox.Show("binary data length = "+binaryData.Length.ToString());
arr.AddRange(binaryData);
}
}
else
{
MessageBox.Show("no rows");
}

byte[] bytearr = new byte[arr.Count];

arr.CopyTo(bytearr);
MessageBox.Show("byte array copied from arraylist="+ bytearr.GetType());

ASCIIEncoding encoding = new ASCIIEncoding();
richTextBox2.Rtf = encoding.GetString(bytearr);//,0,bytearr.Length);

System.IO.MemoryStream stream = new System.IO.MemoryStream((byte[])bytearr);
richTextBox2.LoadFile(stream,RichTextBoxStreamType.RichText);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
MessageBox.Show(ex.StackTrace.ToString());
}
}
}
}
table name->deleteit
fields-->rollno(numeric),rtf(text)
GeneralArchive Mail Reader Pin
Member 21255652-May-05 20:23
Member 21255652-May-05 20:23 
GeneralText Box doesn't show new Value Pin
RobertS.2-May-05 15:53
sussRobertS.2-May-05 15:53 
GeneralRe: Text Box doesn't show new Value Pin
Dan_P2-May-05 16:05
Dan_P2-May-05 16:05 
GeneralUpButton and DownButton methods Pin
JeffHarrold2-May-05 15:52
JeffHarrold2-May-05 15:52 
GeneralRe: UpButton and DownButton methods Pin
JeffHarrold3-May-05 13:11
JeffHarrold3-May-05 13:11 
Generalbrowsing the web from widows application Pin
Modern_night2-May-05 15:29
Modern_night2-May-05 15:29 
GeneralRe: browsing the web from widows application Pin
Christian Graus2-May-05 16:25
protectorChristian Graus2-May-05 16:25 
GeneralRe: browsing the web from widows application Pin
Polis Pilavas3-May-05 3:37
Polis Pilavas3-May-05 3:37 
QuestionPropertyGrid - how to apply changes? Pin
czajajajatoszmaciarz2-May-05 13:04
czajajajatoszmaciarz2-May-05 13:04 
AnswerRe: PropertyGrid - how to apply changes? Pin
Dan_P2-May-05 15:03
Dan_P2-May-05 15:03 
AnswerRe: PropertyGrid - how to apply changes? Pin
Mathew Hall2-May-05 15:03
Mathew Hall2-May-05 15:03 
GeneralRe: PropertyGrid - how to apply changes? Pin
Anonymous3-May-05 10:00
Anonymous3-May-05 10:00 
GeneralRead only Outlookbar Pin
Member 19299502-May-05 12:43
Member 19299502-May-05 12:43 
GeneralRe: Read only Outlookbar Pin
MoustafaS2-May-05 13:14
MoustafaS2-May-05 13:14 
GeneralUrl navigation Pin
Adnan Siddiqi2-May-05 10:42
Adnan Siddiqi2-May-05 10:42 
GeneralRe: Url navigation Pin
leppie2-May-05 14:57
leppie2-May-05 14:57 
QuestionCancellable operation -- recommended practice? Pin
Judah Gabriel Himango2-May-05 9:42
sponsorJudah Gabriel Himango2-May-05 9:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.