|
I've got a treeview/listview pair in a backup program that acts similar to windows explorer, enumerating all drives,folders and files on a PC. I've set it up so there are checkboxes for entries in both controls, so you can select entire folders or just individual files...
I'm wanting to save all the checked items to a "job" file so the backup component can read the job file and perform the backup according to the selections.
Do I have to build this information dynamically (using an array or collection), or do the treeview/lisview controls keep this info around for me?
thanks.
|
|
|
|
|
The .NET treeview has no built-in serialization feature. For more info[^].
|
|
|
|
|
I am trying to redistribute a program that requires both the .net framework and MDAC version 2.6 or higher. I am trying to use microsofts examples of how to create one setup program that will install these components, but i want to use both together. I can implement both seperately but the moethods they give both create a new exe file that test for either MDAC 2.x or the presence of the .net framwork, installs as needed and then continues with my MSI program. the examples check for one OR the other, and the problem is both programs link to the MSI from my application, and I would like to have one setup that does a MDAC search, then goes to the .net search then installs my apps MSI file. anyone know how to do this?
thanks in advance
dan
|
|
|
|
|
A few hints :
First, use only merge modules (*.msm files) provided by MS.
Second, checking the installed MDAC version does not require a thorough procedure. If you use the MS COM Checker (provided in the MDAC MS portal), it's a total mess and quite honestly for most needs this represents 10x times too much overhead. My hint is to check out the dll file version (xx.xx2.yy.yy2 = major, minor, build major, build minor) of one the dlls which happens to be upgraded with all MDAC version : for instance msado15.dll. You've got a MS online article which tells the public version of that dll for each major MDAC release.
Here is the mapping table I use (C code):
typedef struct _MDACVERSION
{
int nMinor;
int nBuildMajor;
char *szPublicName;
} MDACVERSION;
MDACVERSION tabMDAC[] = {
{ 50, 4403, "2.5 RTM" },
{ 51, 5303, "2.5 SP1" },
{ 52, 6019, "2.5 SP2" },
{ 53, 6200, "2.5 SP3" },
{ 60, 6526, "2.6 RTM" },
{ 61, 7326, "2.6 SP1" },
{ 62, 7926, "2.6 SP2" },
{ 62, 7400, "2.6 SP2 Refresh" },
{ 70, 7713, "2.7 RTM" },
{ 70, 9001, "2.7 RTM Refresh" },
{ 71, 9030, "2.7 SP1" },
{ 0 , 0 , "" }
};
|
|
|
|
|
Owner-Draw TreeView with SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint,true);
Problem with the overriden OnPaint methode:
I added two nodes. When the control appears the first time, the OnPaint() methode panits only the first node!? When I move the mouse over the invisible second node then OnPaint draw the second node(but goes through OnPaint twice!?). So the nodes ar only painted when I move the mouse over the nodes. Refresh() or Invalidate() changes nothing.
What could that be? Any suggestions that the TreeView paints its nodes the first time?
|
|
|
|
|
You cannot be using OwnerDrawn support and "ControlStyles.AllPaintingInWmPaint|ControlStyles.DoubleBuffer|ControlStyles.UserPaint" because they are two different, mutually exclusive things.
In Windows you usually can paint a control in three ways:
1- OwnerDraw which is when you handle the OnDrawItema and OnMeasureItem messages. In this situation the control ask you to do the drawing of a particular item at right time. Some of the oldest controls support this techinque: menus, combo box, etc.
2- Custom draw. This is a more fine grained version of the OwnerDraw version, here you have the oportunity to draw just part of the item instead of assumming full resposabilty for the whole drawing. Some of the more sophisticated common controls support this technique: TreeView, ListView.
3-. User Paint: You do the whole drawing yourself. In this case you don't have any help but you have full control as to what to paint. This is what you need to use when you are going to write a control from scratch. This is by far the best technique to write powerful controls because you have totally control of the painting.
One last thing: how are you using OwnerDraw techinque for the TreeView control? As far as I known the TreeView control does not support OnMeasureItem or OnDrawItem methods. You could use CustomDraw but only if you hack the support yourselve using the fact that the .NET TreeView is just a wrapper for the native TreeView control in the Common Control library.
Regards,
Carlos H. Perez
|
|
|
|
|
Thank you very much for answer!
I found now a Sample Solution which seams to be good.
So I will try it with CustomDraw with WndProc(..). But I fear that it will flicker.
It's really a problem that .NET not supplies OnDrawItem and OnMeasureItem for TreeView; that's why I have problems to solve it. I cannot understand this. OwnerDraw is - as I mean - often used; so why these Microsoft Programmers didn't implement it for us?
One question: to do TreeView OwnerDraw with OnPaint(...); how could I do this?
It would be very usefull because I can set the DoubleBuffer Flag and paintings are without flicker. I've tried but there were unlogical things happening; just the first item was painted. The rest of the items were only drawn when I moved the mouse over the other items? Strange.
Can you help me?
Thanks
Stefan
|
|
|
|
|
I use "CustomDraw" on my sample article TreeView control and flickering is almost non existing due in part to some technique that I use to draw the node in a double buffer that I passed to the tree control itself. I don't know what you are looking for but my article show pretty well how to CustomDraw the items.
Regards,
Carlos.
|
|
|
|
|
I've downloaded your article. I had some problems to make it to draw as I like. I could not really understand the following code:
// Set the text and background text color to the window bakcground
// text so that we don't see the text being painted
tvcd.clrText = ColorUtil.RGB(ForegroundColor);
tvcd.clrTextBk = ColorUtil.RGB(BackgroundColor);
But now it works.
Thanks Carlos!
Stefan
|
|
|
|
|
Little problem: I copied your code and made my own TreeNodePainting. When I startup my application I want to select the first node; the first node is selected but not painted in the Focused Colors. When I click into the TreeView (where no nodes are) then the first node is selected. Can you help me what that could be and how to resolve this problem?
Thanks
Stefan
|
|
|
|
|
Hello,
I am trying to use a context menu on a tree view control in my application. The problem is when I right click on an item in the tree view I want my Selection change event of the tree view to fire before the context menu is fired. What is happening is the user is right clicking on a tree node, it is highlighting what they select BUT, the treeview.selectednode was the preivous node they selected! It seems to be many ppl would want to selection change event to fire first?! how can i get around this? thanks alot
S
|
|
|
|
|
Maybe, and I do mean maybe, you could put an Application.DoEvents() at the top of your menus Popup handler, allowing the SelectionChange event to trigger before continuing.
If that doesn't work on its own (because the SelectionChange event doesn't trigger quickly enough) then add a private bool variable, set it in the SelectionChange event, loop through Application.DoEvents() until it's set and then clear it again in Popup.
Just a couple of ideas, I don't know if either will work.
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
Anonymous wrote:
The problem is when I right click on an item in the tree view I want my Selection change event of the tree view to fire before the context menu is fired. What is happening is the user is right clicking on a tree node, it is highlighting what they select BUT, the treeview.selectednode was the preivous node they selected!
This is the expected behavior: try it out in Explorer, if you right click a node it does not select it (it will appear selected, but once the context menu disappears the original node will remain selected).
Rather than relying on the selected node property, you can use the treeview.GetNodeAt method to get the node that was right-clicked on. You can get the current position of the mouse from the MouseEventArgs passed into the MouseDown event handler.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Does anybody knows where to get code for a flicker-free and ownerdraw Treeview?
Thanks
Stefan
|
|
|
|
|
is there anyway i can turn a string (whithout knowing what the string will be)into a exception of that string (for exsample x is System.Exception) how can i perform this case ? any ideas? or would i have to involve something like a foreach statement and i would need to parse though all of the classes within the namespace to compare it to a string.... i have no clue... all help would be much appreciated.
Jesse M
|
|
|
|
|
What are your trying to do exactly? What are comparing to what?
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
well with this program i have all the exceptions that are caught pass to a class with a few atributes being required Expsample...
void Exception(Exception ex,string Title,bool Require close)l
well from the (Exception ex) i can derive the cause of the error into a string. from that string i can run a switch to show the correct error message(by pointing it to the class that deals with the exception).
the string for exsample will say System.NullRefrence exception. I then tell my error(form) to get its data from Say Exception.Message; ect. which works fine. I created my (costom) exceptions class Inheriting from System.Application ,Error, The problem is i couldnt change the Error.Message Property because it was read only. So when i try to get the message property to my costom Form it comes up as null. Basicly what im trying to say is if i can customize this property (Exception.Message, ect) it would solve the problem i have.
here the code i have that i use to inherite from.
<br />
public class BadEncryptionDataException: ApplicationException<br />
{<br />
public BadEncryptionDataException() : base()<br />
{<br />
this.HelpLink="Mailto:Res1s5yd@verizon.net";<br />
}<br />
public BadEncryptionDataException(string message) : base(message)<br />
{<br />
}<br />
public BadEncryptionDataException(string message,Exception inner) :base(message,inner)<br />
{<br />
}<br />
//i clipped the end of it...cause it was to long...but thats the just of it.
Jesse M. How can i costomize the Message property ?
The Code Project Is Your Friend...
|
|
|
|
|
public class BadEncryptionDataException: ApplicationException
{
public BadEncryptionDataException() : this("No message"){}
public BadEncryptionDataException(string message) : this(null){}
public BadEncryptionDataException(string message,Exception inner) :base (message,inner)
{
this.HelpLink="Mailto:Res1s5yd@verizon.net";
}
} Just an OOPsie LOL
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
thats all there is to it then huh ?
The Code Project Is Your Friend...
|
|
|
|
|
jtmtv18 wrote:
thats all there is to it then huh ?
If it does it for yoiu I guess...;P
But have a look what I did in nBASS:
public BASSException() : this(GetErrorCode()){}
internal BASSException(int code) : base(GetErrorDescription((Error)code))
{
err = (Error) code;
} Where GetErrorCode() and GetErrorDescription() is static functions in my Exception class.
To throw an exception, I check for errorstate. Then all I need to do is throw new BASSException() . The Message get inserted automatically. DOnt be afraid to ask more questions.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
I have a few questions indeed actually... i like your method alot better. How did you set it up to add the message in automaticly ? also what are the functions behind the propertys your wrote in your class. How can i get the error code also ? thanks for awnsering my questions by the way. im instrested in setting up a clean and effient error system you know ?
Jesse M...(did i stay up to late? its 1:57 am)
The Code Project Is Your Friend...
|
|
|
|
|
OI what happened to rest of the message
Like said thsoe 2 functions are static and internal to my exception class. Now if you design it nicely, you can have something like this:
public class MyException {
internal enum ErrorCode
{
None,
User,
Programmer,
Unknown,
}
static ErrorCode errorcode = ErrorCode.None;
internal static ErrorCode Error
{
get {
return errorcode;
}
set {errorcode = value;}
}
internal static string GetErrorDescription(ErrorCode code)
{
switch(code)
{
case ErrorCode.User:
return "User error occured, check blah blah for dohdoh";
case ErrorCode.Programmer:
return "Programmer error occured, email blah";
case ErrorCode.Unknown:
return "Unknown error occured, no help available";
case default:
return "No error";
}
}
public MyException():this(Error){}
internal MyException(ErrorCode code):base(GetErrorDescription(code))
{
errorcode = ErrorCode.None;
}
} In you calling code:
...
if (somestring == "badstring")
{
MyException.Error = Error.User;
throw new MyException();
}
... Hope this helps
PS: maybe another helper function:
static void CheckString(string str)
{
if (somestring == "badstring")
{
MyException.Error = Error.User;
throw new MyException();
}
}
...
CheckString("badstring");
...
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
i see said the blind man to his deff dog.....i shall make it work...thanks leppie.. !! i think our time zones / sleep parterns are in perfect sync wouldnt you say ? lol
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
jtmtv18 wrote:
think our time zones / sleep parterns are in perfect sync wouldnt you say ? lol
No, I just woke up, you are going to sleep.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
damn leppie that hole thing really really works great... thanks so much.. i would of NEVER in a million years been able to figure that out !! thanks Alot. it works like a charm ill barely have to change anything in my program to make it work...thanks a hole hell of alot...Can you point me to some articles and such that taught you these things ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|