Click here to Skip to main content
16,014,608 members
Home / Discussions / C#
   

C#

 
QuestionBinding DataGridView to a DataTable - skipping binding some of the columns in the DataTable Pin
Athadu5-Dec-06 14:38
Athadu5-Dec-06 14:38 
QuestionActionscript & C# Pin
Revant Jain5-Dec-06 13:34
Revant Jain5-Dec-06 13:34 
AnswerRe: Actionscript & C# Pin
Vasudevan Deepak Kumar6-Dec-06 0:56
Vasudevan Deepak Kumar6-Dec-06 0:56 
QuestionInserting ListItem controls inside DropDownList controls contained in a Datalist control Pin
tedhill135-Dec-06 12:43
tedhill135-Dec-06 12:43 
Questionsql server 2005 ConnectionString. Pin
hdv2125-Dec-06 11:30
hdv2125-Dec-06 11:30 
AnswerRe: sql server 2005 ConnectionString. Pin
Guffa5-Dec-06 13:31
Guffa5-Dec-06 13:31 
AnswerRe: sql server 2005 ConnectionString. Pin
ednrgc6-Dec-06 7:06
ednrgc6-Dec-06 7:06 
QuestionRichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox Pin
Anthony Queen5-Dec-06 11:23
Anthony Queen5-Dec-06 11:23 
This is a very complex question, so please bare with me.

I'm using VB.net and C# (both vs2003), on a Windows XP machine.

First off, I have some code that allows me to retrieve an IRichEditOle object from a rich text box. With this object, I can insert an object into a RichTextBox control. After inserting the object(s), I can then call GetObjectCount and GetObject to iterate through the Ole objects embedded within the RichTextBox. The code for retrieving the RichEditOle interface and for inserting and retrieving objects (the meat of the application) is written in C#.

I have also written a custom control that inherits from "System.Windows.Forms.Label" and also implements IOleObject. This code is in VB.NET. It is registered for COM Interop and the appropriat guids have been generated. Besides the basic Label functionality, it also eposes extra public properties (strings).

The idea is that a user would be able to insert this custom label control anywhere within a RichTextBox. It works. I can insert and remove multiple controls. I can iterate through the collection of controls in the RichTextBox, cast them back to the custom label, and access each of their properties. It seems to be working perfect.

However, when I save the RTF, and then try to reload, I completely lose the embedded information. Everything else is there, just no custom labels in the RichTextBox. I can open the RTF in Notepad and see that there is embedded information. It saved, but didn't load.

I'm thinking that at least part of my problem might be that I'm not implementing the correct interfaces to allow the custom label to persist itself within the RTB. It might also be that I'm not inserting the object correctly within the RTB. The insertion part is fairly straightforward though. I have a REOBJECT class that I populate and pass to the IRichEditOle::InsertObject(REOBJECT re) method

Here's some of the code:


using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.OLE.Interop;

[StructLayout(LayoutKind.Sequential)]
public class REOBJECT
{
public int cbStruct = Marshal.SizeOf(typeof(REOBJECT)); // Size of structure
public int cp; // Character position of object
public Guid clsid; // Class ID of object
public IntPtr poleobj; // OLE object interface
public IStorage pstg; // Associated storage interface
public IOleClientSite polesite; // Associated client site interface
public Size sizel; // Size of object (may be 0,0)
public uint dvAspect; // Display aspect to use
public uint dwFlags; // Object status flags
public uint dwUser; // Dword for user's use
}



Then, the code for actually inserting (lots omitted for brevity):

ILockBytes pLockBytes;
CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);
IStorage pStorage;
StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage);

IOleClientSite pOleClientSite;
this.IRichEditOle.GetClientSite(out pOleClientSite);

Guid guid = new Guid();

oleObject.GetUserClassID(out guid);

OleSetContainedObject(oleObject, true);

REOBJECT reoObject = new REOBJECT();

reoObject.cp = this._richEdit.SelectionStart;

reoObject.clsid = guid;
reoObject.pstg = pStorage;
reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject);
reoObject.polesite = pOleClientSite;
reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT;
reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE;

this.IRichEditOle.InsertObject(reoObject);

Marshal.ReleaseComObject(pLockBytes);
Marshal.ReleaseComObject(pOleClientSite);
Marshal.ReleaseComObject(pStorage);
}




Any help in solving this is GREATLY appreciated.

Thanks for looking,
Tony






It's only when you look at an ant through a magnifying glass on a sunny day that you realise how often they burst into flames.



GeneralRe: RichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox Pin
Anthony Queen6-Dec-06 5:48
Anthony Queen6-Dec-06 5:48 
GeneralRe: RichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox Pin
ednrgc6-Dec-06 7:13
ednrgc6-Dec-06 7:13 
GeneralRe: RichEditBox, IRichEditOle, IOleObject - Inserting, Saving and Loading embedded Ole objects in a RichTextBox Pin
Anthony Queen7-Dec-06 4:07
Anthony Queen7-Dec-06 4:07 
QuestionListview owner draw question Pin
BudWhite5-Dec-06 9:44
BudWhite5-Dec-06 9:44 
Questionimage drag and drop problem Pin
Kim06185-Dec-06 7:53
Kim06185-Dec-06 7:53 
AnswerRe: image drag and drop problem Pin
Eric Dahlvang5-Dec-06 9:19
Eric Dahlvang5-Dec-06 9:19 
GeneralRe: image drag and drop problem Pin
Kim06186-Dec-06 1:50
Kim06186-Dec-06 1:50 
GeneralRe: image drag and drop problem Pin
Eric Dahlvang6-Dec-06 3:34
Eric Dahlvang6-Dec-06 3:34 
QuestionSqlBulkCopy performance Pin
Jamie Nordmeyer5-Dec-06 7:53
Jamie Nordmeyer5-Dec-06 7:53 
AnswerRe: SqlBulkCopy performance Pin
Vasudevan Deepak Kumar6-Dec-06 0:59
Vasudevan Deepak Kumar6-Dec-06 0:59 
Questionhow to manage the click event of a dom node (ie an image) in a iexplorer web page ? Pin
lulaleila5-Dec-06 7:47
lulaleila5-Dec-06 7:47 
QuestionC# Array Problem Pin
neptune2k5-Dec-06 6:53
neptune2k5-Dec-06 6:53 
AnswerRe: C# Array Problem Pin
User 66585-Dec-06 7:21
User 66585-Dec-06 7:21 
AnswerRe: C# Array Problem Pin
Ravi Bhavnani5-Dec-06 7:23
professionalRavi Bhavnani5-Dec-06 7:23 
AnswerRe: C# Array Problem Pin
Private_Void5-Dec-06 7:29
Private_Void5-Dec-06 7:29 
AnswerRe: C# Array Problem Pin
Guffa5-Dec-06 7:42
Guffa5-Dec-06 7:42 
GeneralRe: C# Array Problem Pin
neptune2k5-Dec-06 8:44
neptune2k5-Dec-06 8:44 

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.