|
-
Sep 16th, 2003, 04:23 PM
#1
Thread Starter
Hyperactive Member
Database OLE object in a Richtextbox *[RESOLVED]*
I've created a DB in Access with two fields: Questions - A text field, and Answers - an embedded WordPad OLE document.
I want what's in the embedded wordpad field to be displayed in a RichTextBox (this is because I use bold, italics, bullets, colours, etc in the Answers) but I don't know how!
I've attached the DB to VB (!) using the connections and adapters but I just can't fathom out how to display the WordPad OLE embedded object in a RichTextBox. Here's what I'm using to fill a listbox with the Question field:
Code:
DsPlatform1.Clear()
OleDbDataAdapter1.Fill(DsPlatform1)
but i'm getting an exception error on the second line, I'm brand spanking new at DB with VB so please be gentle!
Thanks.
Last edited by RealNickyDude; Sep 18th, 2003 at 01:32 PM.
-
Sep 16th, 2003, 04:35 PM
#2
You should store the richtext from wordpad in the db as text, probably a memo type field. Then in the RichTextBox you just assign that to the RTB property and you're done. That seems like it would be much easier.
-
Sep 16th, 2003, 04:37 PM
#3
Thread Starter
Hyperactive Member
Howdee Edneeis!
But how would I indicate text attributes and colour in the memo type field?
-
Sep 16th, 2003, 05:00 PM
#4
All of the bold, italic and whatever, style settings are part of the richtext. If you opened a wordpad document in notpad you'd see it looks like {{\f0,Arial}\b1This is bold\b0} so you just put those codes in the database then assign them to the RTF property of the Richtextbox and they will show up with the same bold, italic and whatever settings.
-
Sep 16th, 2003, 05:29 PM
#5
Thread Starter
Hyperactive Member
Thanks Edneeis, I get what you mean but how do I set it to the RTF property? Is it in the property list? All I get is the codes as well as the text.
-
Sep 16th, 2003, 05:41 PM
#6
If you get the codes and the text then you probably set it to the Text property of the RichTextBox, which is incorrect you want the RTF property which will take the RichText (codes and texted together) and display it properly. Yes Rtf is a property of the richtextbox.
-
Sep 16th, 2003, 05:46 PM
#7
Thread Starter
Hyperactive Member
Sorry to be a pain, but what does it come under?!?! I can't find anything in the properties list at the side to change it from text to RTF!!!!
-
Sep 16th, 2003, 06:06 PM
#8
Rtf is not shown in the properties dialog to the right, but it is a property of the RichTextbox, I promise.
You can either set it in code:
RichTextBox1.Rtf=MyRtf
Or if you want to use Databinding still then you can do that through code, once:
RichTextBox1.DataBindings.Add("Rtf", ds.Tables(0), "FieldNameHere")
-
Sep 16th, 2003, 06:14 PM
#9
Thread Starter
Hyperactive Member
Now i'm getting:
VB Code:
C:\My Programs\VisualBasic\GMCQADatabase\Form1.vb(384):
Reference to a non-shared member requires an object reference.
This is what i've got (I'm just guessing here as I haven't much of a clue 
VB Code:
rtbPlatformTextBox.DataBindings.Add("Rtf", DPlatform.Tables(2), "Answer")
DPlatform = name of table
Answer = Field 2(?) - I have ID, Question then Answer so i'm guessing it will be a 2?
Edit: Does Tables[0] mean the first table if you had many?
-
Sep 16th, 2003, 06:17 PM
#10
The datatable should be the datasource. So try something like:
rtbPlatformTextBox.DataBindings.Add("Rtf", DsPlatform1.Tables("DPlatform"), "Answer")
The parameters should be
1- The name of the property on the object to bind to (in this case the 'Rtf' property)
2- The datasource (in this case it would be the table that has the 'Answers' field)
3- The datamember (in this case it would be the name of the field in the datasource/table that you want to get the data from, or 'Answers')
Last edited by Edneeis; Sep 16th, 2003 at 06:21 PM.
-
Sep 16th, 2003, 06:24 PM
#11
Thread Starter
Hyperactive Member
Weird, I deleted DPlatform1.Tables(0) that I had (as it didn't work) then tried the one in the above post, which obviously didn't work either.
I then retyped DPlatform1.Tables(0) again, and now it works!!
Here's the line.
VB Code:
rtbPlatformTextBox.DataBindings.Add("Rtf", DPlatform1.Tables(0), "Answer")
Hmmm......
Anyway, extreme thanks to you Edneeis for all your help and patients, I'll probably return sometime with a bag full of questions.
Thanks again.
-
Sep 16th, 2003, 06:26 PM
#12
No problem, glad to help.
Now you can add a how to do databinding section in your code book.
-
Sep 17th, 2003, 01:34 AM
#13
Thread Starter
Hyperactive Member
I thought I had this solved, but I don't. I have this in the Form_Load:
VB Code:
DPlatform1.Clear()
OleDbDataAdapter1.Fill(DPlatform1)
rtbPlatformTextBox.DataBindings.Add("Rtf", DPlatform1.Tables(0), "Answer")
When I run the program, the first answer is show as it should, in true RTF format, but If I click on another question, the richtexbox just goes blank, even clicking back on the first question still keeps the richtextbox blank.
both questions do have the rtf format, how come the answers are blank?
-
Sep 17th, 2003, 09:40 AM
#14
I don't know how are you changing records?
-
Sep 18th, 2003, 10:45 AM
#15
Thread Starter
Hyperactive Member
Of course, sorry
I'm using a listbox, this is filled with questions; field 2 from the database (field 1 is the ID key). When the user clicks on a question from this list, the answer (field 3) is displayed in a Richtextbox.
The answer will contain text effects, bold, italic, bullets, different colours, etc to point out various things as well as pointing out bits of code.
There is an online version of the Questions & Answers, although it's HTML, you can see the sort of thing i'm trying to do as a program (as it will include tutorials, and other things): http://gmc.madladdesigns.co.uk/questions/contents.htm
II've attached the program as it stands, not very much, but i've just started.
-
Sep 18th, 2003, 10:53 AM
#16
Originally posted by RealNickyDude
II've attached the program as it stands, not very much, but i've just started.
-
Sep 18th, 2003, 10:59 AM
#17
Thread Starter
Hyperactive Member
Bah! I can't seem to attach it! But you can download it from here: GMC Database
-
Sep 18th, 2003, 11:35 AM
#18
They way the IDE autogenerated the binding for the listbox was different from the way I showed you for the RTB. Just change this line:
VB Code:
rtbPlatformTextBox.DataBindings.Add("Rtf", DPlatform1.Tables(0), "Answer")
to this:
VB Code:
rtbPlatformTextBox.DataBindings.Add("Rtf", DPlatform1, "Platform.Answer")
Also you have the path to your db hardcoded in so it has to be recompiled with a new path if it is moved to some else's machine. If you put the path in the bin folder or the same folder as the exe then you can use this to make it movable.
VB Code:
Public Sub LoadDB()
DPlatform1.Clear()
'change the connection strings
OleDbDataAdapter1.SelectCommand.Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & IO.Path.Combine(Application.StartupPath, "gmc.mdb")
OleDbDataAdapter1.InsertCommand.Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & IO.Path.Combine(Application.StartupPath, "gmc.mdb")
OleDbDataAdapter1.UpdateCommand.Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & IO.Path.Combine(Application.StartupPath, "gmc.mdb")
OleDbDataAdapter1.DeleteCommand.Connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & IO.Path.Combine(Application.StartupPath, "gmc.mdb")
OleDbDataAdapter1.Fill(DPlatform1)
'Name of display object("rtf text", name of table.tables(0), "which field to display")
rtbPlatformTextBox.DataBindings.Add("Rtf", DPlatform1, "Platform.Answer")
End Sub
-
Sep 18th, 2003, 12:55 PM
#19
Thread Starter
Hyperactive Member
Thanks Edneeis, I've copied the various bits, but now there's another problem: I click on the second question and everything's ok, the text comes up with the correct text effects, I then click on the first question again and the text appears ok, but without the text effects; bold, bullets, clicking on the questions from then on produces the text, but not with the effects.
-
Sep 18th, 2003, 01:18 PM
#20
Oh yeah I forgot something. You had bound the "text" property of the Richtextbox to the data too, in the IDE. You should remove that. You only want the Rtf bound not the Text.
-
Sep 18th, 2003, 01:32 PM
#21
Thread Starter
Hyperactive Member
Thanks Edneeis, it's all sorted now thanks to you, everything seems ok (until next time )
Thanks pal!
Looks like i'll have to buy myself the Dummies Guide to VB.Net Databases
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|