|
If I understand what you want correctly, without walking the entire tree yourself, no there isn't.
Every TreeNode supports its own TreeNodeCollection. So you just have to walk the entire collection of each node and add it to your seperate TreeNodeCollection.
|
|
|
|
|
No, I don't think such method exists. You don't have to create a custom tree view for this, just write an extension method[^] (assuming you're using C# 3.0).
Eslam Afifi
|
|
|
|
|
public void GetNodes(TreeNodeCollection tc)
{
foreach (TreeNode tn in tc)
{
MessageBox.Show(tn.Text);
GetNodes(tn.Nodes);
}
}
I know nothing , I know nothing ...
|
|
|
|
|
Ok I did it this way, any comments?
<pre>
public class G31TreeView : TreeView
{
private static TreeNodeCollection allNodes;
/// <summary>
/// Returns all nodes, including childs (a flattened tree)
/// </summary>
public TreeNodeCollection AllNodes {
get
{
allNodes = new TreeNodeCollection();
return BuildAllNodesList(this.Nodes);
}
}
/// <summary>
/// Builds the list of all nodes recursively
/// </summary>
/// <param name="tnc">The initial node to begin the build</param>
private void BuildAllNodesList(TreeNodeCollection tnc)
{
foreach (TreeNode tn in tnc)
{
// If the list hasnt added the current node we add it.
if (!allnodes.Contains(tn))
{
allnodes.Add(tn);
}
// Childs of current tn
BuildAllNodesList(tn);
}
}
}
</pre>
|
|
|
|
|
That'll work, but there's really no need for the check to see if the node exists already. A TreeNode cannot exist in more than one place in the tree.
|
|
|
|
|
The project in which i am doing, i need to dynamically change the font of the label control and i did it and i saved the values in the database (ms-access). And now i need to retrieve those values from the database . So, i have retrieved the values but how can i apply those retrieved values to the label font dynamiacally. Give me some solution.
|
|
|
|
|
myLabel.Font = new Font(....................);
Look up the documentation for the Font constructor. There are loads of them, which one to use will depend on what information you saved in your database.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
I have written a COM DLL which gives the
out parameter as BSTR**(Typically 2D Char Array).
This COM function will fill the values of BSTR** variable.
I am able to use this function sucessfully in MFC Application.
But I face problem in using it in C#.
The Sample code is as follows:
///////////COM Function////////////////////////////////////////
STDMETHODIMP CSampleTest::GetAllDeviceList2(BSTR** szMaclist)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
for(int i=0;i<10;i++)
{
szMaclist[i] = new BSTR[100];
wchar_t *szTmp = new wchar_t[100];
wsprintf(szTmp,L"Device%d",i+1);
*szMaclist[i]=SysAllocString(szTmp);
}
return S_OK;
}
///////////////////////////////////////////////////////////////
I acessed this in VC++ by,
BSTR **szMaclist = new BSTR*[10];
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,iid,(void**)&pText);
if( SUCCEEDED(hr) )
{
pText->GetAllDeviceList2(szMaclist);
pText->Release();
}
and i am sucessful in acessing this function in MFC Application.
Can anyone tell me how to acess GetAllDeviceList2() function in c#.
|
|
|
|
|
Generate a COM Class Wrapper (CCW)[^] then add reference to that in your .net project and invoke. Probably you will get a 2D array of object (i.e. object[][] ) for that BSTR**.
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
If you don't mind could you please provide me the code snippet
for the above.
|
|
|
|
|
when a PDF file is opened, AcroRd32.exe is started automatically, and we get the GUID value of that adobe reader.
In c#, can't we get the document associated with the GUID value, I mean the total PDF file which is opened in adobe reader at runtime.
Here I'm struck up in code, can anyone suggest how to where I was missing something.
Acrobat.CAcroAVDoc AcroAvDoc;
Type AcrobatCAcroType;
AcrobatCAcroType = Type.GetTypeFromCLSID(new Guid("{CA8A9780-280D-11CF-A24D-444553540000}"));
Object obj = Activator.CreateInstance(AcrobatCAcroType);
AcroAvDoc = (Acrobat.CAcroAVDoc)obj;
I think I can get the full PDF document with AcroAvDoc.GetPDDoc();
Thank you...
|
|
|
|
|
Hello,
i can't find function that handles a convertion to ipicture object to byte[]
greetings,
Sander
|
|
|
|
|
IPicture? What's that? Not that thing in COM?
Regards,
Rob Philpott.
|
|
|
|
|
yeah that COM (system.__comobject) i need to convert it to byte[]
greetings,
Sander
|
|
|
|
|
Well, I steer clear of COM like the plague so can't help, but the COM forum might be a better place to try.
Regards,
Rob Philpott.
|
|
|
|
|
If the MSDN declarations are anything to go by, then I would Render it to a device context, create a Graphics object from that device context, then somehow draw that onto a Bitmap. When you've done that, you can save it to a MemoryStream (which is basically just a wrapper for a byte[] anyway)
However, I'm just getting this from MSDN. I can't help you with writing the code, just a possible theory
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
I'm using a couple of API calls that require function pointers for callbacks.
So far I've been passing in a delegate instance and it's worked fine. I'm concerned that the delegate reference however may be changed in managed memory. On researching this I came accross the Marshal.GetFunctionPointerForDelegate method.
Some people say this is not needed as passing the delegate directly invokes the internal version of this anyway. Other's suggest that pinning the delegate or the class instance that contains it is necessary.
All MSDN has to offer is "You must manually keep the delegate from being collected by the garbage collector from managed code."
Has anyone had total success (or occaisional failures) just passing the delegate instance directly, or recommend a robust approach?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
I strongly suspect .NET pins function parameters for you when there is a need to do so, of course only for as long as the native function is being called. This applies to:
- strings you pass to a const char*
- StringBuilders you pass to a char*
- delegates you pass to a function pointer
- etc.etc.
I have been doing this all along. I only use GCHandle to explicitly pin down things that need to remain natively in use after the native function returns, such as buffers that will be used asynchronously.
I've never used Marshal.GetFunctionPointerForDelegate(); I suspect the only real use for it is when a delegate is buried inside a larger structure. Same seems to apply for a lot of stuff in the Marshal class.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi Luc,
Thanks, pretty much confirms what I thought. I've found a little more MSDN documentation to support this too so I can rest more easily
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Just a quick follow up Luc...
The delegate is a parameter in an Open function. To keep the instance alive, I have a private static list of open devices and the instance is added to that.
The callbacks can keep coming until the Close function is called. When closing, I'm removing the instance from the static list. I've also implemented the Dispose pattern on the device instances and if any are open when Dispose is called, the Close function is called. Doing it this way seems to remove the need for any pinning etc.
Is that sufficient in your opinion?
(I haven't managed to call the Close without runtime errors from a finalizer BTW, so if you know a solution to that I'd be glad to hear it! I can post code if you wish).
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Dave,
DaveyM69 wrote: To keep the instance alive, I have a private static list of open devices and ...
That should be fine, although I would probably prefer to have the delegate as an instance member of your device object, rather than in a static list. I probably would also have a static list of devices, either just for debugging or to make sure they remain alive if that's useful. Or I would try and create such device objects with a using construct provided that fits the overall software architecture.
DaveyM69 wrote: I haven't managed to call the Close without runtime errors from a finalizer
That doesn't ring any bells (maybe the symptoms are too vague to ring anything). I trust you are aware all finalizers are ran from a single low-priority thread in the GC (not necessarily soon), and having a finalizer throwing uncatched exceptions is (or at least has been) a bad idea. That reminds me it has been a long time I researched finalizers...
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Luc Pattyn wrote: prefer to have the delegate as an instance member... have a static list of devices
That's what I meant, I just didn't describe it that well! This code is to be consumed elsewhere so the using would be tricky to implement here - but easy for the consumer.
The Close from the finalizer is a strange issue. It works fine (I think) if the finalizer is called during normal execution, but if called when a consuming application closes (and so releases all references) it causes the problems. I don't have the code with me right now but will post a snippet later when I get home (this is a hobby not work project - the best kind ).
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I just made a complete sample ready to post here, and calling Close in the finalizer is working without error!
Must have something else causing the problem in the original code - thanks for your time anyway!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
perseverance is king!
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|