|
Thanks for checking out this post. Here is my issue. I am trying to build a tree view with data stored in a database table. The table is simple, it contains a folder id, name and parent id. The root folders will all have a parent id of zero (0). If a record has a parent id other than 0 then I want to creat that folder as a child folder of the parent linking them on parent id = folder id. In VB6 this was totally possible, because you had to come up with the key that made the folder unique. I haven't been able to find out how this is done in C#, can anyone help point me in the right direction?
|
|
|
|
|
Why wouldn't this be possible? It's a mere concept. I've done this in our application and to a very advanced and complex degree using strongly-typed tree nodes and trees, which it needn't be. It's actually an easy problem.
Loop through your data source (say, a DataSet ) recursively starting with nodes that have the parent ID as 0. Create that node and add it to the TreeView.Nodes collection. Then (before moving to the next parent node, hence the recursion) find the nodes that have the parent ID set to the ID of the node you just added. Call the same procedure again, which will create each node, add it to the TreeNode.Nodes collection of the node you just added, and then will find it's children. For the example below, I assume that a DataSet was passed to my method:
public void BuildTree(DataSet ds)
{
DataRow[] roots = ds.Table[0].Select("ParentID = 0 OR ParentID IS NULL");
foreach (DataRow root in roots)
{
BuildTreeHelper(root, myTreeView.Nodes);
}
}
public void BuildTreeHelper(DataRow row, TreeNodeCollection nodes)
{
TreeNode node = CreateNodeFromData(row);
nodes.Add(node);
DataRow[] rows = row.Table.Select("ParentID = " + node.Tag);
foreach (DataRow row in rows)
BuildTreeHelper(row, node.Nodes);
}
public TreeNode CreateNodeFromData(DataRow row)
{
TreeNode node = new TreeNode();
node.Text = row["Name"];
node.Tag = row["ID"];
return node;
}
This is the basic gist of it, and in most other languages, since real languages allow for recursion!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi all, I hope that someone will be able to help me.
I have installed the DirectX 9.0b SDK and started the Sample Browser to test some of the samples. But all the samples throw a FileNotFound exception when launched - File or assembly name Microsoft.DirectX.Direct3D, or one of its dependencies, was not found. or similar. What am I doing wrong? All Managed DirectX assemblies are installed and located in the \WINNT\Microsoft.NET\Managed DirectX\v4.09.00.0900 folder.
Any clues are highly appreciated! Thanks in advance.
Rado
|
|
|
|
|
Well, based on what I have found in the discussion board for the Managed DirectX Tutorial[^], I have tried to install the DirectX developer runtime separately (because I have installed the componentized DirectX SDK for C#, not the complete DirectX SDK) and after this, the Microsoft.DirectX.* assemblies appeared in the "Add Reference" dialog of VS.NET 2003.
I still cannot run the precompiled samples that came with DirectX SDK, but I can compile the sample projects and run the samples this way!
Rado
|
|
|
|
|
There is one important thing you should understand: what VS.NET sees (in the Add References dialog) and what's in the Global Assembly Cache (GAC) are different. The GAC is what's important here. You should open the directory (using Start->Run) %WINDIR%\Assembly and see if you see the DirectX assemblies in there. If they aren't, there's your problem.
See, the CLR searches for assemblies differently that Win32. It checks the assembly bindings in the config file, then the private path (usually the app directory or a "bin" subdirectory), and then it searches the GAC. You'll notice that the DirectX assemblies are neither referenced in the config file nor are they in the private path (and I don't mean the PATH env var, which doesn't matter to the CLR). If they aren't in the GAC, that's why they're not found.
What VS.NET is seeing is actually assemblies not in the GAC, but in folders referenced in the registry, namely HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework . I don't know why they do it that way, but they do. So, just because you see it in VS.NET doesn't mean that the sample can find them. They have to be in the GAC for that.
So, you need to make sure that the GAC contains those assemblies. If not, I'm surprised that running the developer runtime setup didn't do it. Check on the DirectX web site because I know that there were several patch-like updates to DirectX 9.0 (the first release) that fixed problems with both A and B. A straight B install might not install the managed assemblies. The web site should be able to help.
Good luck!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks a lot for a detailed explanation. You were right, I don't know why, but the assemblies are not in the GAC. These are the steps I've taken to install the SDK:
1. Install the DX 9.0b redist over DX 8.1 redist (didn't have the SDK at that time).
2. Install the DX 9.0b SDK for C#.
3. Install the DX 9.0b dev runtime.
Perhaps I will try to reinstall the complete SDK package (not only the SDK for C# version) later today.
Anyway, thanks again for the info!
Rado
|
|
|
|
|
I would like to know how to get the handle of the currently active window. I've tried using Findwindow and it works, but i want the whole view of the active window (including the toolbar and menubar) as i would like to create a program to take a screenshot of the active window (something like ALT+PRINTSCREEN but using BitBlt to do the capturing).
|
|
|
|
|
I'm not sure what problems you're having, but the typical way is similar to the following pseudo code:
HWND hWnd = FindWindow(NULL, "MyApp");
RECT rc;
GetClientRect(hWnd, &rc);
HDC hDC = GetDC(hWnd);
HDC hCDC = CreateCompatibleDC(hDC);
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;
BitBlt(hCDC, 0, 0, width, height, hDC, 0, 0, SRCCOPY | CAPTUREBLT);
Is this what you're doing (roughly)?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yeah more or less. Here's the exact code :
hWnd = FindWindow(null, "Form1");
RECT rc = new RECT();
GetWindowRect(hWnd, ref rc);
this.Text = "LEFT" + rc.left + " RIGHT " + rc.right + " TOP " + rc.top;
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetDC(hWnd);
BitBlt(dc1, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);
ReleaseDC(GetDC(hWnd)), dc2);
GC.Collect();
Graphics gr = Graphics.FromHwnd(pictureBox1.Handle);
pictureBox1.Image = myImage;
|
|
|
|
|
Hi,
I´m playing a .wav file through a buffer with CSound. How do I get hold of the actual sound raw data in the buffer in order to do DSP on them? I´ve tried with GetBuffer(), but I can't get it to work.
/Thanks
|
|
|
|
|
hi, how i can achieve functionality of Gantt Chart like in MS Project using C#..is ther any library...or i have to code it separately..? pls tell me soon..-bhavin
|
|
|
|
|
I would hope that you searched the Internet first. A search of "gantt chart C#" on google yielded many results, including one here on CodeProject that mentioned Dundas, one of the sponsers of CodeProject and admittedly a decent library development company.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
thanx for the reply Heath. u r right...i searched on the net first...but i found so many links which has their own library..i mean all are third party controls..while i want to use it in my academic project..so, if any library of C# is available then it would help me..otherwise i will have to create the component..which takes time...
pls tell me if u have any idea for that..and yeah..i want to create network diagram also...so, what should i do? i have to create component or default library facility is there...if yes then please give me the details...thanx again..
-bhavin
|
|
|
|
|
What's wrong with using a library? That's the whole point of libraries - reuse.
Besides, if you include the code in yours and the code is copyrighted (and it most likely is), you run the chance that 1) you get sued, 2) you fail the course and / or are expelled from school (most schools will), and 3) you're going against everything OOD and shared libraries stand for.
If you're assignment is to create a Gantt chart, then what you want to do is cheating and I won't be party to that. If you only need to use a Gantt chart for your assignment, then just use a library. There are free ones out there and you should simply use the assembly. .NET assemblies (of these nature) don't require any installation, so any copy operations that the TAs require should just grab the assembly in which the Gantt chart is created. My old university's turn-in script let us upload all appropriate files, be they source or libraries (back then, only C/C++ static and dynamic libs).
You should talk to your TA or professor if you have concerns about using a third party control. If you hesitate because they might fail you for cheating, then you definitely shouldn't use it and start looking for information on programming basic grids and lines (which really isn't that hard for a basic Gantt chart).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
What's the difference between destructor and finalize? And is there any way that I can step thru code in destructor or finalize?
Thanks!
norm
|
|
|
|
|
norm wrote:
What's the difference between destructor and finalize?
Whatever code you put into your destructor would get renamed to a method called Finalize in the generated IL. There is a method generated called __dtor which is the actual class destructor and which can be thought to look something like this (imaginary projection only and not to be taken as it is) :-
void __dtor()
{
GC::SuppressFinalize(this);
Finalize();
}
protected virtual void Finalize()
{
}
Regards
Nish
Extending MFC Applications with the .NET Framework [NW] (My book with Tom)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
Come with me if you want to live
|
|
|
|
|
Thanks, but why'd do we need destructor then? I mean, all the code in destructor will be transferred to Finalize() in IL anyway.
Also, when I tried to implement Finalize in my C# class, i got this CS0249 error, the compiler wont let me implement/declare Finalize?? Anyway, here is an extract from MSDN:
*************************************************************
QUOTE MSDN:
Do not override object.Finalize. Instead, provide a destructor.
Use destructor syntax to specify instructions to execute when your object is destroyed.
See Using C# and Managed C++ Destructor Syntax for more information.
The following sample generates CS0249:
// CS0249.cs
class C
{
protected override void Finalize() // CS0249
// try the following line instead
// ~C()
{
}
public static void Main()
{
}
}
norm
|
|
|
|
|
In a Garbage Collected programming environment like the CLR, it's not very smart to put clean-up code in the destructor because you do not have much control over when it gets called. MS recommends that you implement IDisposable and put all your clean up code in the Dispose method. And as for the error you got, the C# compiler wont let you implement Finalize because they rename the class Destructor method to Finalize in the generated IL.
Nish
Extending MFC Applications with the .NET Framework [NW] (My book with Tom)
Summer Love and Some more Cricket [NW] (My first novel)
Shog's review of SLASMC [NW]
Come with me if you want to live
|
|
|
|
|
I want to make sure all threads of the application is aborted before the object goes out of scope. Now, I'm writing a control. I do not want to place the burden to call Dispose in my client's code since it's a UI control that I'm writing. The remaining choice is destructor. I pretty much gave up on Finalize because compiler keep bugging me. The only remaining option is:
~myclass()
{
if(m_Thread.ThreadState!=System.Threading.ThreadState.Stopped)
m_Thread.Abort();
... the rest of it...
}
What can I do in a destructor in .NET - besides releasing memory? I know I can't even Console.Write() in a destructor with .NET (although that won't generate a bug) - same applies for Thread.Abort()??
norm
|
|
|
|
|
If your threads have the IsBackground property set to ture, when all foreground threads are terminated the background threads will automatically be aborted.
norm wrote:
What can I do in a destructor in .NET - besides releasing memory?
Not much, basically you can only use value types. Typically you use a destructor in .NET for freeing unmanaged resources, which are typically held by an IntPtr to represent the handle returned by windows.
James
"My words but a whisper -- your deafness a SHOUT.
I may make you feel but I can't make you think." - Thick as a Brick, Jethro Tull 1972
|
|
|
|
|
|
I am trying to use a c++ api from C# code. I know how to import DLL's, and also about tlbimp, but what is the mechanism for importing a .lib file.
Thanks
Trevoe
|
|
|
|
|
I guess you need to wrap your lib API into Managed C++ lib (assemblies)? This is what I will do.
Not sure of this. Would like to find out as well.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
I have 2 binary numbers, NO. I have 1 binary number...
01010011
Now, how would I convert that to hex? I.E. (53)
convert this bin number...
11111111
into this... (FF)??
/\ |_ E X E GG
|
|
|
|
|
Convert class may be useful for you. If not, maybe you have to write your own convertor
Don't forget, that's Persian Gulf not Arabian gulf!
|
|
|
|