|
Whenever you add a node, get its full path and store it into node's name.
<br />
TreeNode tn = this.treeView1.Nodes.Add("AAA");<br />
tn.Name = tn.FullPath;<br />
When you want to expand the node having, let's say, "The_wanted_path"
you use this:
TreeNode [] tn = this.treeView1.Nodes.Find("The_wanted_path", true);
if ( tn[0] != null )
{
TreeNode Parent = tn[0].Parent;
TreeNode FirstParent = Parent;
while (Parent != null)
{
Parent = Parent.Parent;
if (Parent != null) FirstParent = Parent;
}
tn[0].Expand();
if (FirstParent != null) FirstParent.Expand();
}
SkyWalker
|
|
|
|
|
How can i assign any values to datagridcombobox cell?
Thanks
|
|
|
|
|
<br />
for(int i = 0;i<10;i++)<br />
{<br />
dataGridView1.Rows.Add();<br />
DataGridViewComboBoxColumn mycol = new DataGridViewComboBoxColumn();<br />
mycol.Items.Add("i");<br />
dataGridView1.Columns.Add(mycol);<br />
}<br />
<br />
Ufff, again i answared it
|
|
|
|
|
Hi,
How do you stop listview columns been able to be resized? I want to lock the column sizes.
Thanks in Advance.
Rapier503
|
|
|
|
|
Add the handler for the ColumnWidthChanging event. Be it private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
Then put these 2 lines of code inside:
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
{
e.Cancel = true;
e.NewWidth = -1;
}
SkyWalker
|
|
|
|
|
Greetings!
I have two fields, one int and one string. The string stores an integer value. I have to check these fields for equality. I don't know if I should compare them as integers or as strings.
I'm more for string comparison, since then I don't have to worry about getting an exception (as opposed to using Int32.Parse), so I don't need to use a try-catch block. Then again, the string gets its value as someint.ToString(), so parsing it shouldn't throw any Exceptions. Also I think comparing two integers should be a bit faster then is the case with strings. Any thoughts on the subject?
|
|
|
|
|
You should of course not store an integer as a string in the first place, but I assume that you know that, and that the storage is out of your control...
Comparing integers are of course faster than comparing strings, but I'm not sure that the actual comparison is a large enough part of the entire operation for that to make any real difference.
To compare the values as strings you have to be absolutely positive that the format of the strings are always exactly the same, as the strings "42", " 42", "042", "42.0" and "0x2a" won't be equal although they contain the same value.
---
Year happy = new Year(2007);
|
|
|
|
|
As I said before, the string is actually someint.ToString(). To be more precise, I'm actually getting a hidden field value in ASP.NET, which is of course a string. Since I set the value of the hidden field (on the client side), I also know the format, which happens to be the plain "42" type. Obviously in this case favoring one comparison over another doesn't actually make a difference at all. I was just curious if someone knows a best practice for this kind of problem. Perhaps in the future I will come across a similiar situation, where the differences in comparison time do matter. It's just like those someString.Length > 0 vs. someString != String.Empty questions.
[edit]Actually the problem is pretty much like the problem I mentioned as an example, as I am willing to except a third choice, if possible, like String.IsNullOrEmpty(someString) is for the example above [/edit]
-- modified at 9:33 Friday 12th January, 2007
|
|
|
|
|
Well, if you only have one string value and a lot of integers, then you should obviously convert the string to an integer.
Look at the number of string operations that you have to do to using different methods. Integer comparisons are so cheap in comparison that they can be ignored.
If you convert the string to an integer, you have a single string operation. If you convert the integers to strings, you will have one string operation per value.
If you on the other hand had a single integer value to compare to a lot of strings:
If you convert each string to an integer and the compare the integers, you have one string operation per value. If you convert the integer value to a string and then compare that to each string, you have one string operation per value plus an additional string operation. In this case the methods will cost about the same.
---
Year happy = new Year(2007);
|
|
|
|
|
You do not have to worry about exceptions if you use Int32.TryParse().
I would go for integer comparison.
SkyWalker
|
|
|
|
|
szukuro wrote: I'm more for string comparison, since then I don't have to worry about getting an exception
if the string must contain a value representing an int then you have to worry about.
Moreover, if you compare strings maybe you don't get what you expect, for instance:
" 15" is not equal to "15" .
Cheers
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Well if the two strings can be the same and then the integers of the strings will be the same. But if you use lets say: Convert.ToInt32(string val) part of the System? namespace. If the ints are the same then the strings should be the same. The may be some circumstances or possibly exceptions if the string you are trying to convert has letters and numbers in them.
string a, b;
a="123"
b="123"
a equals b - when comparing the string values
Convert.ToInt32(a) equals Convert.ToInt32(b) - when comparing the integers of the string
a="L123"
b="L123"
a equals b - when comparing the string values
Convert.ToInt32(a) does not equal Convert.ToInt32(b) - will probably cause an exception or it may convert the letter 'L' to asc, I'm not real sure
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi Friends
How to add images into dropdownlist using (C#,ASP.NET).
Pls help me
Thank you
Prabhakaran
|
|
|
|
|
See this:
http://www.codeproject.com/vb/net/ImagesComboBox.asp
Compile it to DLL and use it from your application in .NET
|
|
|
|
|
example:
Assume that i have Form1 and From2.Form1 is the main program and Form2 is a sub page of the program.When i press "Properties Button" in Form1,Form2 will show above Form1.So in this case we can't interact with Form1 until we have already done something in Form2 then click 'OK'.Now Form2 is now closed and we back to the main program(Form1).
something like this....How to do this in VC#.net2005
thank
Aonz
PS. Sorry with my English skill
|
|
|
|
|
Form2 needs to be treated as a dialog. To do this (from Form1):
Form2 dlg = new Form2();
if (dlg.ShowDialog() == DialogResult.OK)
{
.. Do something here.
}
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
bug_aonz wrote: So in this case we can't interact with Form1 until we have already done something in Form2 then click 'OK'
You're talking about a modal form. Calling ShowDialog will do this.
Overall, I recommend buying a book on Winforms and C# and working through it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
i have a disconected imviroment database application, and normaly i need some validation rules for the data-entry part. i am using the invalidate event to check if the data is in the correct format. the problem is i want to be able to close the form is the data is not in the correct format, but i am not able to because the control refuses to lose focus until the data is in the correct format.
please help
rzvme
|
|
|
|
|
Your question really answers itself.
You have made the choise that the control should not lose focus until the format is correct. Therefore you can not escape from the control until the format is correct.
The solution is of course that if you don't want the control to work that way, you change the control so that it doesn't work that way.
Implement the validation on form level instead of on field level.
---
Year happy = new Year(2007);
|
|
|
|
|
but can i at least find out if the form is trying to get the focus so it can close, or another control is trying to get the focus?
rzvme
|
|
|
|
|
Hi, Dear Respected Programmers
I need basic help about Datagrid that How may I :-
1) create new columns and rows manually
2) add value manually
3) change or edit cell value
4) remove columns
5) remove selected columns
your corporates will be highly appreciated.
Thank you in Advance
-- modified at 5:53 Friday 12th January, 2007
|
|
|
|
|
Have you seen the DataGrid(View) articles at CodeProject? Also see this[^] MSDN link.
/ravi
|
|
|
|
|
hi
in my application initially one button event occurs due to that it executes some function during that function execution if i press any character on the keyboad my keypress event should execute instead of completing the button pressed event code.
how can i do that please help
thanks in advance.
|
|
|
|
|
I guess that you have to write control inheriting from the control youre using now and override the KeyPress envent
sth like this:
protected override void OnKeyPress(....){
if(your stuff){
....
}
else
base.OnKeyPress(e);
}
life is study!!!
|
|
|
|
|
Conceptually, the Windows GUI architecture works by having a message queue containing the list of inputs a window has received and a message pump that pops items off the queue and executes their corresponding handlers one by one. In your case, the keypress event will be put in the queue and won't be processes until the button click handler completes.
To get around this, you could delegate the button click handler code to a separate thread. This way, the button click handler returns quickly and the message pump processes your keypress. Of course, you would still need to code the handler of the keypress event and abort logic of the button click handler.
|
|
|
|