|
leppie wrote:
Here you can add some string or number and use that to check for equality, not the actual TreeNode objects
could you please explain a bit more i dont follow you
thx
|
|
|
|
|
currentNode = new TreeNode(Path.GetFullPath(ofd.FileName));
currentNode.Tag = Path.GetFullPath(ofd.FileName);
if(CheckNode(currentNode)){
Then
private bool CheckNode(TreeNode node)
{
string test = (string) node.Tag;
foreach (TreeNode n in treeView1.Nodes)
if (n.Tag == node.Tag)
return false;
return true;
}
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
Your code is written well, but Contains() does not do what one might expect it to.
I have had exactly the same problem, and lost a lot of hair researching this. The CLR TreeView has no way of finding a node by name, even though the Contains() method looks like it would provide that functionality. Contains() returns true only if the node passed to it, is the exact same node as one already in the TreeNodeCollection. I do not see a lot of use for such functionality, but that is the way it is.
What we are interested in is a way to see if there is already a node with a specific name (or full path). There are a number of ways of testing this, and most rely on enumerating some nodes, and seeing if one of the names matches the one being sought. Incidentally, a TreeNodeCollection can contain multiple nodes with exactly the same name, which might be one reason searching for a "unique name" was not implemented.
In your case, it looks as though each node's name contains full path info, so this might not be too difficult. In my case, I had nodes branched-out into dir trees, which required parsing each path into separate dir names, and walking the tree.
Anyway, I enumerated by grabbing the node returned by FirstNode, which gets a node's first child node. With the node returned (if not null), I kept calling NextNode to get the rest of the child nodes. I did this until null was returned (no more child nodes). If there is a match, continue deeper if necessary, using the same methods (I used recursive calls).
In my case I wrote a search function that took an array of node names, which were parsed from the path to look for. I hope some of this helps.
Cheers
|
|
|
|
|
Thank you Both Jeff J for that great comment and help and Leppie for explanation and the code
I appreciate it
Amir
|
|
|
|
|
i use sharp develop most the time these days...(cant afford vs yet ) anyways i try get say a icon that i want embedded in my dll to embedd but it doesnt seem too do it. (im a total newb when it comes to embedding anyway)can someone help me by supply code too get me on my feet? i have never used reflection but i want too use it so i can put all my icons in one neat little dll. please supply code for embedding and then calling a iconfile (and say setting it too...this.Icon or something) if you have the time it would really really really help me out.. thanks alot.
Icon File Name : Icon_Question.ico
P.s: i tryed reading the article's on reflection at the codeproject but it wasnt explained clear enough lol.. i can understand pure code just fine though (is that strange?)
jesse M
|
|
|
|
|
I think you are looking for resources, not reflection . That mite help you, unfortunatley I havent worked with it before
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
ResourceReader
taken from .Net Sdk Documentation
i found out how too use the ResourceReader/writer but it doesnt cover the problem
<br />
using System;<br />
using System.Resources;<br />
<br />
public class SampleClass<br />
{<br />
public static void Main()<br />
{<br />
IResourceWriter rw = new ResourceWriter("MyResources.resources");<br />
rw.AddResource(@"C:\myPrograms\NetText\icons\icon_10.ico", "Stop");<br />
rw.AddResource(@"C:\myPrograms\NetText\icons\Icon_Question.ico", "Question");<br />
rw.AddResource(@"C:\myPrograms\NetText\icons\Icon_14.ico", "Folder");<br />
rw.Close();<br />
}<br />
}<br />
<br />
i noticed that resource reader only makes a resource file points too a perticular directory / file which doesnt help me...cause im trying too keep my icons hidden so if someone deletes them..the program wont keep throwing exceptions.. and ideas leppie ?
email me at : res1s5yd@verizon.net if u need more info or anything leppie.
jesse M
|
|
|
|
|
OK some more info from MSDN ms-help://MS.VSCC/MS.MSDNVS/cptutorials/html/image_resources.htm[^], sorry I cant help anymore without actually learning how to use resources.
Image Resources
To create image resources, perform the following three steps:
Create an XML-based .resx file containing the named resources.
Convert the .resx file into a .resources file using Resgen.exe.
Create a DLL, and embed the .resources file using the Assembly Generation Tool (AL).
Note For more information on AL, see Appendix B: Resource Tools.
As with strings, if the image resources are localized into nondefault cultures, the process must be done for each culture — which must also be specified when using AL — as well as for a default, language-neutral culture.
The first step — creating the .resx file — is more complicated with image resources. There are several methods for doing this, but ultimately the resource must be converted into ASCII text using BASE64 encoding and embedded into an XML-formatted .resx file.
ResXGen — A handy tool for converting resources is the ResXGen utility included with this tutorial. This small console application takes three arguments: the name of the image file, the .resx output file, and the name to give the resource. The following command line is from the Build.bat file for the Graphic sample application:
ResXGen /i:un.jpg /o:Images.resx /n:flag
A more complete description of this tool, including a discussion of the source code, can be found in Appendix B: Resource Tools.
ResEditor — Another tool for converting resources is the ResEditor utility included with this tutorial. This Windows Forms application allows to you add and delete resources — including bitmaps, icons, and strings — that are located in .resources files. By using a property browser, ResEditor allows you to explore the properties of graphic resources and directly edit string resources.
To illustrate how to use this tool (which might not be completely obvious), you can now walk through the process of creating a common .resources file that combines the German resources from the WorldCalc and Graphic samples discussed earlier. Start ResEditor, and open MyStrings.de.resources from the \de subdirectory of the WorldCalc sample directory for either Visual Basic or C#. Note that the string name/value pairs are listed in the property grid. In the Add group of controls near the bottom of ResEditor, type flag, and click the Add button (which will no longer be disabled). A new node is added to the tree of controls and properties that is on the left. Select the new flag node, and click the ellipsis button (…) that is just to the right. Navigate to the \flags subdirectory of the WorldDocs sample, and specify the de-DE.jpg image file. Note that the properties for the Flag bitmap are now shown as a thumbnail image — in this case, of the German flag. You should now see something like the following illustration.
Resource Editor (RESEDITOR) (from the Appendix B link)
The Resource Editor (ResEditor) sample application is also a useful tool. It provides a graphical interface that allows you to construct .resources files containing bitmaps, icons, and strings.
It appears RESEDITOR is a sample app included with the SDK samples. You might be required to build it 1st.
ANyways hope this helps
PS: JTJ had an article/post a few months back if I remember correctly, not sure if that would help.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
leppie wrote:
JTJ had an article/post a few months back if I remember correctly, not sure if that would help.
Not really, my article covers using VS.NET and the commandline; but I don't know anything about SharpDevelop...but I may have to install it just so I can add more to the article
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Jesse,
Not sure if this is exactly what you're looking for, but in addition to what leppie said, you can embed the .resource file (generated by resgen) in your assembly using /res <resource file="" name=""> in your csc command and then read it back again using
Assembly ass = Assembly.GetCallingAssembly();
Stream strm = ass.GetManifestResourceStream("MyResourceFile.resources");
IResourceReader rr = new ResourceReader(strm);
IDictionaryEnumerator de = rr.GetEnumerator();
while (de.MoveNext())
{
} (This requires System.Reflection and System.Resources)
Paul
Pleasently caving in, I come undone - Queens of the Stone Age, No One Knows
|
|
|
|
|
Hi all,
The function below is used to filter out messages in a DataSet depending on wheather they are between the two dates; "DateTime from" and "DateTime to".
The date of the message is the first column of each row.
(logDataSet is a global variable)
I'm having trouble with this line:
tempDS.Tables["Table"].Rows.Add(logDataSet.Tables["Table"].Rows[i]);
in the below code.
I get the following exception:
"System.ArgumentException
This Row already belongs to another table"
Also, I have tried creating an copy of the DataSet logDataSet (DataSet tempDS = logDataSet), but when I delete rows from the copy it seems to also delete these rows from the global DataSet logDataSet.
Does anyone have any ideas where I am going wrong?
Thanks,
Donal
<br />
private DataSet filterDates(DateTime from, DateTime to)<br />
{<br />
DataSet tempDS = logDataSet.Clone();<br />
for(int i=0;i < logDataSet.Tables["Table"].Rows.Count;i++)<br />
{<br />
DateTime fromTime = (DateTime)logDataSet.Tables["Table"].Rows[i][0];<br />
DateTime toTime = (DateTime)logDataSet.Tables["Table"].Rows[i][0];<br />
if( fromTime.Date >= from.Date && toTime.Date <= to.Date)<br />
{<br />
tempDS.Tables["Table"].Rows.Add(logDataSet.Tables["Table"].Rows[i]);<br />
}<br />
}<br />
return tempDS;<br />
}
|
|
|
|
|
I suggest using a DataView as a filter - or -
From MSDN:
DataTable.NewRow Method
See Also
DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | Add | DataColumnCollection | DataColumn | DataRowCollection
Creates a new DataRow with the same schema as the table.
[Serializable]
public DataRow NewRow();
Return Value
A DataRow with the same schema as the DataTable.
Remarks
You must use the NewRow method to create new DataRow objects with the same schema as the DataTable. After creating a DataRow, you can add it to the DataRowCollection, through the DataTable object's Rows property.
- or -
Copy the value directly from the DataRow's ItemArray property.
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
I tried to integrate a flex program with C# the way I used to integrate with VB6 but nothing is happening.
I want to know the correct way to do it. Is there any DLLs I have to attach?
Anybody know abt this? Pls help me.
Thanks.
kind rgds,
Anjana Aluthwala
|
|
|
|
|
If you give more details perhaps someone can help you, if you repost it, no one will. To be honest I dont even know WTF you are talking about , FLEX (is it some kind of aerobics exercise?) never heard of it. VB6 never touched it. Maybe post some VB6 code in the VB.NET forum. Just dont repost!!!!
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
I have to write a program in c#,recently. However I don't know what to write about.I think it may be about socket programing. But in fact, there are still too much we can write using sockets. Still, I want to write something new. Can you all help me, and give me some sugguestion? Think you all.
|
|
|
|
|
Anything on Remoting or using Managed DirectX A C# CodeDom codeparser will be nice while you are at it
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
I vote for Yacc and Lex.
Вагиф Абилов
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
Hi all,
How do I convert the current value of a DateTimePicker control to a DataTime object?
Thanks
Donal
|
|
|
|
|
From MSDN:
DateTimePicker.Value Property
See Also
DateTimePicker Class | DateTimePicker Members | System.Windows.Forms Namespace | DateTime
public DateTime Value {get; set;}
Property Value
The DateTime value assign to the control.
Remarks
If the Value property has not been changed in code or by the user, it is set to the current date and time (DateTime.Now).
Example
The following example demonstrates how use the Value property to retrieve the current date value. First, the example displays the Value property. The example then increments the Value property by one day and displays the property value again.
public MyClass()
{
DateTimePicker dateTimePicker1 = new DateTimePicker();
Controls.AddRange(new Control[] {dateTimePicker1});
MessageBox.Show(dateTimePicker1.Value.ToString());
dateTimePicker1.Value = DateTime.Now.AddDays(1);
MessageBox.Show(dateTimePicker1.Value.ToString());
}
Who is this miscrosoft, and what devilish plans have they for us?
|
|
|
|
|
|
Hi:
I’m an intermediate level C#.net programmer and I found your email address at www.dotnet247.com … My difficulty is parsing a Log File into a SQL database. The RegEx looks very interesting; however I would like a sample code to learn with. Help….
This is a sample from a typical Log File. The “Headings” (Date & Time, etc) above the Log File entries are NOT in the actual file. I placed them there to represent my SQL database table columns I would like to “Break” the information into...
| Date & Time | Activity | Source IP | Dest IP | Reason |
Wed, 01/15/2003 10:29:03 - TCP connection dropped - Source:211.218.37.114, 3017, WAN - Destination:206.104.18.112, 1433, LAN - 'Suspicious TCP Data'
Wed, 01/15/2003 11:01:25 - UDP packet dropped - Source:200.11.88.226, 64546, WAN - Destination:206.104.18.112, 137, LAN - 'Suspicious UDP Data'
Wed, 01/15/2003 11:08:05 - TCP connection dropped - Source:198.87.196.145, 53, WAN - Destination:206.104.18.112, 1177, LAN - 'Suspicious TCP Data'
Wed, 01/15/2003 11:38:08 - UDP packet dropped - Source:65.167.107.117, 1027, WAN - Destination:206.104.18.112, 137, LAN - 'Suspicious UDP Data'
Wed, 01/15/2003 14:26:02 - TCP connection dropped - Source:208.186.78.104, 80, WAN - Destination:206.104.18.112, 2563, LAN - 'Suspicious TCP Data'
Kevin@upgrade1.com (Please reply to email address)
|
|
|
|
|
The BeginListener function will not receive any information from the socket
past a certain amount (apparently 4096 bytes). Information sent that is
smaller than that is received properly. If data is sent that is larger than
that, it's truncated to 4096 bytes, and then the while loop exits (which it
should never do).
<br />
private void BeginListener()<br />
{<br />
byte[] b = new byte[10000000];<br />
int k;<br />
Socket s;<br />
String strMessage = "";<br />
<br />
TcpListener newList = new TcpListener(10000);<br />
newList.Start();<br />
while (true)<br />
{<br />
strMessage = "";<br />
<br />
s = newList.AcceptSocket();<br />
k = s.Receive(b);<br />
<br />
for (int nCounter = 0; nCounter < k; nCounter++)<br />
{<br />
strMessage += (char)b[nCounter];<br />
}<br />
}<br />
newList.Stop();<br />
}<br />
<br />
<br />
private void SendCommand(String Address,String strTempFile)<br />
{<br />
StreamReader newReader = new StreamReader(strTempFile);<br />
String strSendString = newReader.ReadToEnd();<br />
newReader.Close();<br />
<br />
newClient = new TcpClient();<br />
NetworkStream tcpStream = null;<br />
byte[] ba;<br />
<br />
try<br />
{<br />
newClient.Connect(Address,10000);<br />
tcpStream = newClient.GetStream();<br />
ASCIIEncoding asem = new ASCIIEncoding();<br />
ba = asem.GetBytes(strSendString);<br />
tcpStream.Write(ba,0,ba.Length);<br />
}<br />
catch (System.Net.Sockets.SocketException)<br />
{<br />
}<br />
finally<br />
{<br />
if (tcpStream != null) {tcpStream.Close();}<br />
if (newClient != null) {newClient.Close();}<br />
}<br />
}<br />
Any help would be greatly appreciated.
|
|
|
|
|
You should never read this much information in one read. Many servers don't even send information that fast and your socket times-out while waiting. Buffer your respones into byte[4096] (a good recommended size) and write them out to a stream (using the read byte count) as they're read-in. This is how practically every transport mechanism works.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
First of all, there no such limitation in the .NET Socket implementation : the actual code beinh Receive() is in fact a direct Winsock2 recv() function call, and it passes your buffer directly, not an intermediate buffer.
I can see an error in your code : in your loop, you are Accepting a new socket instance at each iteration. Usually, you accept a socket once, and then loop with Receive.
|
|
|
|
|
I have a Bitmap that has loaded in a map. When I click on the map (bitmap), I want to draw a filled circle at that point. I understand how to do it with a PictureBox or something that I can get a Graphics object for/from it, but I can't for the life of me figure out how to do the same with a bitmap.
Is there a way to do this? I'm sure there is, I just haven't figured it out yet. So, if any of you could help me out by pointing me in the correct direction, code fragments, or whatever, I'd really appreciate it.
Thanks a bunch!
Mike
|
|
|
|
|