|
Hi,
I have a placed a TreeView control in my application.
On the after select event i wanted to know which element was selected to do something with it:
<br />
private void tvLibrary_AfterSelect(object sender, TreeViewEventArgs e)<br />
{<br />
TreeView tree = (TreeView) sender;<br />
MessageBox.Show(node.Name)); <br />
} <br />
The thing is that the message box comes blank.
What am i doing wrong?
Thx,
Nuno
|
|
|
|
|
hi
discover the e parameter e.g e.Node.Text or e.Node.Tag
The e.Node is the selected Node
regards
|
|
|
|
|
ohhh
Of course!!
Thx,
Nuno
|
|
|
|
|
Hi again,
Now that i have the name of the node i want to see if its a directory or if its just a file.
A directory has more nodes below, and a file doesnt.
What i did was:
<br />
TreeNode next = null;<br />
next = node.NextNode;<br />
<br />
if (next!=null)<br />
{<br />
MessageBox.Show(node.Text);<br />
}<br />
else<br />
{<br />
MessageBox.Show("Doesnt have");<br />
}<br />
But this has a strange behaviour...
When i click a file, it shows a message box with the name of the file.
When i click in a folder, it shows a message saying i "Doesnt have"
Once again... what am i doin wrong?
Thank you very much.
Nuno
|
|
|
|
|
the behaviour isn't so strange.
When I looked up the .NextNode method in the object browser, it said:
"Summary: Gets the next sibling tree node."
MSDN Treenode[^]
Siblings are on the same level as the current one, it is not a child.
instead of
if (node.NextNode != null)
you should check
if (node.Nodes != null) ...<br />
if (node.FirstNode != null) ...
or
if (node.Nodes.Count > 0) ...
(I'm not sure whether it is initiallized when it's zero. Probably safest to use
if (node.Nodes != null && node.Nodes.Count > 0)
I hope this will get you the desired functionality.
|
|
|
|
|
Hi,
I have just noticed that i dont have a consistent Tree.
I want to implement a tree to explore a directory which is going to be a library of files.
This is the code i have for it to be filled:
<br />
<br />
if (!Directory.Exists("Library"))<br />
{<br />
Directory.CreateDirectory("Library\Flash");<br />
Directory.CreateDirectory("Library\Image");<br />
Directory.CreateDirectory("Library\Movie");<br />
Directory.CreateDirectory("Library\Url");<br />
}<br />
<br />
private void initializeTree()<br />
{<br />
tvLibrary.Nodes.Clear();<br />
tvLibrary.Nodes.Add(new TreeNode("Library"));<br />
TreeNode tNode = new TreeNode();<br />
tNode = tvLibrary.Nodes[0];<br />
<br />
populateTree(Application.StartupPath + @"\Library", tNode, 0);<br />
tvLibrary.ExpandAll();<br />
}<br />
<br />
private void populateTree(string root, TreeNode inTreeNode, int level)<br />
{<br />
TreeNode tNode;<br />
<br />
try<br />
{<br />
if (root.CompareTo("") == 0)<br />
return;<br />
<br />
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(root);<br />
<br />
DirectoryInfo[] dirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles();
<br />
foreach (System.IO.DirectoryInfo di in dirs)<br />
{<br />
inTreeNode.Nodes.Add(new TreeNode(di.Name));<br />
<br />
tNode = inTreeNode.Nodes[level];<br />
populateTree(root + @"\" + di.Name, tNode, level + 1);<br />
}<br />
<br />
foreach (System.IO.FileInfo fi in files)<br />
{<br />
inTreeNode.Nodes.Add(new TreeNode(fi.Name));<br />
}<br />
}<br />
catch (System.Exception err)<br />
{<br />
MessageBox.Show("Error: " + err.Message);<br />
}<br />
}<br />
I detected two problems. If i have files in the Images directory they appear normally, under Images sub folder inside the main node, Library.
However, if i have files under Movies, or Urls folders, those files appear under the Images sub folder.
The other problem is that if create a folder inside the Images folder, a error happens, which i think its about the level depthness.
I tried to understand this tree concept but its quite strange.
Can someone try to expalin me what is going on?
Thx,
Nuno
|
|
|
|
|
I think one of your problems lies here:
tNode = inTreeNode.Nodes[level];
I looked into it (yes I have too much time) and that's the only line I couldn't really get. There is no relation between the level variable, and the position of the desired node in the nodes Array.
You should instead use this, I think (works here, with c:\temp dir):
<br />
foreach (System.IO.DirectoryInfo di in dirs)<br />
{<br />
TreeNode tn = new TreeNode(di.Name);<br />
<br />
<br />
populateTree(root + @"\" + di.Name, tn, level + 1);<br />
<br />
inTreeNode.Nodes.Add(tn);<br />
}<br />
Also, I wouldn't use recursion, because it makes your code needlessly complicated
public object BufferOverFlow<br />
{<br />
__get { return BufferOverFlow; }<br />
__set { BufferOverFlow = value; }<br />
}
|
|
|
|
|
Situation:
I'm working on an application (C# in .Net 2.0) where the user is able to enter some sensitive data (eg passes) in the options.
This sensitive data has to be stored in a secure (encrypted) manner - so that nobody outside the application can read the data - but of course the application itself should be able to read it on later occasions.
First I thought an encrypted xml would be fine, but then the key for encryption has to be shared - an idea I really don't like - even when the key is encrypted as well (then the key for the key must be shared).
Hash encryption is no option for me, because I don't like to bother the user with a password entry on startup, or something like that, when everything is alread entered in a previous session via the options.
Question:
How do applications like Outlook or instant messanger do store sensetive data (like mail server passes)- via an encrypted good hidden file? or is it a registry entries? or something else?
I'm open for everything, as long the sensitive data is stored in a safe manner; and if your ideas do circle around encrypted xml or hash it's not a problem for me - maybe I took the wrong approach concerning those two.
Thx in advance
|
|
|
|
|
I'd say that encryption is the only way.
Maybe you could specify your application a little more, or at least the type of sensitive files that you're using.
I'm not an expert in the/any field, but some of the ideas that came into my head would be to.
use hashes even though you don't really want to, to make a single security checkpoint
use Active Directory functionality and protect files the NT Way
use encryption (don't know much about that...)
use an external server to handle these request that is completely closed off from the rest of the network... sorta like an LDAP.
(this is my first answer on the message boards, so go easy )
|
|
|
|
|
Hi
I don't think you have many more options than save the password in an encrypted file with a keyfile that lies around on you pc, because if you want to read encrypted data, you need to know how to decrypt it.
the way i understand it, outlook does the same.. there's probably a file on your hd with the encrypted user - data in it.
you know, the local security is not the main problem here. the problem begins when you send password over the network to a server.
let's say you have a pc with your e-mail passwords saved on and you log on to your mailserver. your e-mail - client does the following:
it connects to the pop-server and says:
user someone@somedomain.org
pass 123456
the whole communication is in cleartext, so everyone can listen! and that's where security acutally IS imporant.
in e-mail (POP) you have 2 possibilities to solve that problem:
1. APOP works like this:
you connect to the pop server and say
apop someuser
the server answes something like:
+OK <1laksjjf23098234987sdj>@somedomain.org
now you take the text behind the +ok and add the password to it, calculate an md5 hash of it and send that to the server. then no one is able to read the password.
i'm not quite sure about the exact procedure of apop but it's well documented in the RFC 1939
2. possibility is to use securePOP (ssl)
just connect to the pop-server over the securePOP - Port with an ssl stream and use the normal pop - commands.
so. short said:
don't do security at the wrong place. it's ok when you encrypt files locally but if YOU can read a file that is locally saved on your pc, anyone, who has physical access to your pc can. security mostly is a network - Problem. so, whenever possible use either secure connections (ssl, ...), or use authentication - methods that allow you to send only (password + salt) - hashes over the network.
greets
m@u
|
|
|
|
|
|
Thx guys - I will rethink the whole issue and will consider your comments while then.
Cheers
|
|
|
|
|
Hi,
I have a small question. I have some variables with almost the same name. For example:
<br />
string message_108 = "fngfh";<br />
string message_109 = "88";<br />
string message_110 = "22";<br />
.....<br />
string message_200 = "ffb";<br />
All I want is to create some kind of method which receives the number of the message (e.g. 110) and that returns the description(value) of that message (message_110).
Can you give me any suggestions.
Do your best to be the best
|
|
|
|
|
Well, this sounds like a homework question. Why would anybody else want to use variable names like that? If you really wanted to use *indexed* versions of the variable, you would use an array of some description.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Actually it's not a homework, and I've tried with arrays and arraylists but I need another way that this could be done.
Do your best to be the best
|
|
|
|
|
karkster wrote: I've tried with arrays and arraylists but I need another way that this could be done
Then we need to look at the bigger picture, because at the moment what you are doing does not make any sense.
|
|
|
|
|
Let me put it in another form. I want to access a Property of a class, but I have the name of the property in a string.
Do your best to be the best
|
|
|
|
|
Use reflection. There are numerous examples on Google on how to do this. Hint - look at GetType().GetProperty(...).GetValue(...)
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Have you thought of using reflection? Reflection won't work with local variables, but will work with properties.
|
|
|
|
|
Thanks. It works with Reflection.
Do your best to be the best
|
|
|
|
|
Rework it into an array or hashtable.
|
|
|
|
|
Use reflection. Because you are using members you will have to use FieldInfo not PropertyInfo.
Of course, like others have mentioned, I would use a hash instead of members.
File Not Found
|
|
|
|
|
Hello everybody.
In my C# project I have a dataGridView with 12 Columns and 16 Rows.
Propertie ColumnHeadersVisible is set true;
How to enter value(text) into Cell between Row headers and Column headers (Cell in Topleft corner) in my dataGridView?
Thanks in advance.
|
|
|
|