|
|
Hi I am adding several labels and textboxes at runtime in a panel. How can i get only the text present in the textboxes? That is i need to identify the textboxes only. thanks
|
|
|
|
|
Iterate through each controls in panel and check it is a textbox.
foreach(Control control in panel.Controls)
{
if(control is TextBox)
{
(control as TextBox).Text;
}
}
|
|
|
|
|
|
HI,
Any one who can help me. how can i get a file icon, all i have are a filenames. I read about SHFILEINFO, but is there other way of retrieving the icons with out using that one?]
I'm doing a 'windows explorer'-like application in c#,web application.
Thanks!
|
|
|
|
|
I dont think so. SHFILEINFO seems to be the best way, otherwise you could analyse the registry and try to retrieve the values from there.
Der Staat mit der niedrigsten Geburtenrate ist nicht die Bundesrepublik, sondern der Vatikan.
|
|
|
|
|
|
hai,
how to do vote rating concept in .net with c#.if you know the concept or link send to me..
thank you.
|
|
|
|
|
If we understood the question it would help.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hello everyone,
For this best practices rule,
http://msdn.microsoft.com/en-us/ms182172.aspx
What are the benefits of following this rule even if I am not wrapping an unmanaged resource, like FileStream in the sample in the page.
I think it is fine if the class does not implement IDisposable, since FileStream could be disposed (to release the native file handle) since it has its own Dispose method. Any ideas?
thanks in advance,
George
|
|
|
|
|
George_George wrote: What are the benefits of following this rule even if I am not wrapping an unmanaged resource,
No benefit. If you have nothing to dispose, why implement IDisposable ?
|
|
|
|
|
Thanks N a v a n e e t h!
In the MSDN sample, what is the benefit of class HasDisposeMethod, if it implements IDisposable (as shown in the sample)?
regards,
George
|
|
|
|
|
It wraps FileStream and provides dispose pattern to dispose FileStream instance. In that example, they have initialized FileStream, but not disposing after use. When you call Dispose() on a HasDisposeMethod instance, FileStream instance will get disposed. If HasDisposeMethod was like the following, no need of IDisposable implementation.
public class HasDisposeMethod
{
public HasDisposeMethod()
{
}
public void UseFileStream()
{
using(FileStream newFile = new FileStream(@"c:\temp.txt", FileMode.Open))
{
}
}
} In the above example, FileStream instance is used and disposed after user. So no need to provide dispose interface.
|
|
|
|
|
Thanks N a v a n e e t h,
Great reply! One further question, for the original sample in the MSDN page, if it does not implement IDisposable, what are the issues?
regards,
George
|
|
|
|
|
FileStream won't be disposed until GC collects.
|
|
|
|
|
Thanks N a v a n e e t h!
So, you mean the benefit is -- if the wrapper class implements IDispoable, we could enforce "using" block on the wrapper class to Dispose the resource immediately?
regards,
George
|
|
|
|
|
Yes. It's always good to call Dispose() if it is provided.
|
|
|
|
|
Great N a v a n e e t h!
Question answered.
regards,
George
|
|
|
|
|
This issue is with respect to Windows Application
I have 2 comboBox in the same row of a DatagridView. When I attach an event one of them, the other comboBox also fires the same event. How can I attach an event only to a particular combo in a DataGridView
|
|
|
|
|
Make use of the sender argument. Check sender is the required combobox. If yes, continue processing.
|
|
|
|
|
what's the diffrence between these two declarations:
ObjectType objectName;
ObjectType objectName=null;
|
|
|
|
|
The first statement means that you are going to declare an object and the second statement mean you are going to dispose an object. If you want to dispose an object then you assign null to that object.
|
|
|
|
|
arslanjatt wrote: The first statement means that you are going to declare an object and the second statement mean you are going to dispose an object. If you want to dispose an object then you assign null to that object.
This not correct. Both means same. Also you don't need to assign NULL to an object which you want to dispose. It is handled automatically and an object will be garbage collected when nothing is referring it.
|
|
|
|
|
Hi Navaneeth,
Do developers consider it good practise to always initialise an instance to null when they are declared?
For example, if I always declared variables, and set them to null as below:
<br />
Class class1 = null;<br />
would it be bad practice and/or any slower than:
<br />
Class class1;<br />
|
|
|
|
|
Hello Mark,
MarkBrock wrote: Do developers consider it good practise to always initialise an instance to null when they are declared?
I am not sure, but I never used to assign NULL when it is declaring.
object obj;
object obj1 = null;
Console.WriteLine(obj == null);
Console.WriteLine(obj1 == null); This won't compile. Compiler will give error saying obj is not assigned. So easily I can find out uninitialized variables. But if you assign NULL to it and forget to initialize, compiler won't give any error, but you will end with a NullReferenceException at the runtime. I think performance wise there won't be any difference.
|
|
|
|