|
packmichael wrote: Visual Studio 2004
Must have missed that release.
only two letters away from being an asset
|
|
|
|
|
Ha ha. Sorry, make that Visual Studio 2005. I have changed the original post to avoid any future confusion.
|
|
|
|
|
how to disable arrow keys on grid to fire any event.
without inharit grid class.and override processcmdkey
event.
amit
|
|
|
|
|
|
Don't cross post it is an abuse of the sites resources. Also neither of the forums you posted this in is the correct one. Good luck
|
|
|
|
|
I have a windows app and on form_load i am calling a funciton that is building a list but this function gets called on other ocassions also (when there is change in data (i.e. add, update or delete)). I want to raise an event when I have the item.Name available so I can populate the drop down box with the item names.
So essentially I want an OnItemLoad event to be fired and when its fired I want the drop down box to populate the items.
for (int i = 0; i < Category.Length; i++)
{
#region This section needs to be replaced by the event
if (populateCategoryDropDownList)
{
ddlCategory.Items.Add(Category[i].CategoryName);
}
#endregion
...
txtControl.AutoCompleteCustomSource.Add(temp);
...
}
I have tried working with examples available on msdn etc but it gets soo confusing! this seem like a very simple task but I just can't seem to figure it out. Please help !
|
|
|
|
|
What is "item.Name"?
Do you need an event, or do you just need to call the method that builds your list from other events, like Load?
only two letters away from being an asset
|
|
|
|
|
Sorry, Item.Name = Category[i].CategoryName
Item being a drop down list item.
This can be done with a call to a method but there is some other stuff that can be accomplished once I have a specific category available. I tried to omit the details out to keep the question simple.
But for argument's sake, for each category there are several other child records that need to get processed. Some of them are shown on the UI and some of them are more like calculation type results.
I thought using event would simplify the process and would also increase the performance (not sure if this is true) by completing the task on a separate thread.
Thanks
|
|
|
|
|
Events are an implementation of the observer pattern. They are used to notify an interested party that something has happen to an object that they have expressed an interest in knowing about. Events don't increase performance, however, can certainly decrease it if not used properly. From what I can see from you description you don't need to use events.
You should also do more research before trying to use a technique you are unfamiliar with. Learn when and why to use, and when not to use it.
only two letters away from being an asset
|
|
|
|
|
Hi,
Can somebody tell me what are all the limitations of the constructor of a struct?
Is it possible to declare an ordinary writeline statement in its constructor?
Regards,
Lenus.
|
|
|
|
|
I am sure it is in the documentation of a struct what the limitations of a struct are.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
ok. Thnx. What abt the second question? Is it possible? I tried but it isn't working. I felt quite strange at this.
Regards,
Lenus.
|
|
|
|
|
To declare actually means to define which would mean object WriteLine; is a valid answer. I think the professor means, can you call System.Diagnostics.WriteLine; experimentation will yield the answer just make sure you are building in debug mode with a console application first.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
No I just want to print out something from the struct's constructor which is not happening. Why is it so?
Regards,
Lenus.
|
|
|
|
|
|
I tried. Its not possible from the constructor I create for a value type (declared without new keyword) struct.
Regards,
Lenus.
|
|
|
|
|
Limitation is that structs cannot contain explicit parameterless constructors. But you certainly can use Console.WriteLine in sturct's constructor. See this example:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Test t = new Test(7);
Console.ReadLine();
}
}
public struct Test
{
public Test(int x)
{
Console.WriteLine("I'm Test's constructor and this is my x parameter: "+ x.ToString());
}
}
}
|
|
|
|
|
Yes it is possible only if the struct is instantiated (as if it was an object). Not in the other case when we declare it without the new operator(as if it was a value type variable).
Any suggestions?
Regards,
Lenus.
|
|
|
|
|
It seems as if the constructors don't perform any other work than to assign fields withe values when created as a value type(without new operator).
Regards,
Lenus.
|
|
|
|
|
SPanicker* wrote: Not in the other case when we declare it without the new operator(as if it was a value type variable).
Now I know what you were asking, it was not clear from your initial post. In that case, default parameterless constructor is called and as I said before you cannot declare or override paremeterless constructor.
|
|
|
|
|
Even in this case, the constructor(which i provide) is getting read and the values are assigned.
Only exception is that,I cannot call any other functions from inside that( But values can be assigned to variables ).
I still need two points to be cleared:
As you said if the parameterless constructor cannot be overridden then how is this happening?
If the parameterless constructor cannot be overriden, then why is C# designed to accept such constructors which are of no use?
Thanks.
Regards,
Lenus.
|
|
|
|
|
You declare(override) parameterless constructor? I'm lost here, can you past piece of code with your struct?
|
|
|
|
|
Hi Michal,
Sorry what i meant was, I have a constructor for a (value type - declared without new keyword) struct.
This constructor cannot invoke any inbuilt functions like Console.WriteLine or user defined ones. But at the same time it can do assign values for fields. This seems quite strange.
But, the same things works well(from inside the constructor)if it is declared with the new keyword.
Pls. chk this sample code and tell me if somethngs wrong:
using System;<br />
<br />
struct newStruct<br />
{<br />
public newStruct(int a)<br />
{<br />
Console.WriteLine("In newStruct");<br />
Console.WriteLine("{0}",a);<br />
}<br />
}<br />
struct anotherStruct<br />
{<br />
public int x;<br />
public anotherStruct(int a)<br />
{<br />
Console.WriteLine("In newStruct");<br />
x = a;<br />
Console.WriteLine("{0},{1}",a,x);<br />
}<br />
public void method1()<br />
{<br />
Console.WriteLine(x);<br />
}<br />
}<br />
<br />
class AppEntry <br />
{<br />
<br />
<br />
public static void Main()<br />
{<br />
newStruct abc = new newStruct(10);<br />
anotherStruct def;<br />
def.x= 250; <br />
def.method1();<br />
}<br />
}
Regards,
Lenus.
|
|
|
|
|
Hi Lenus,
there is nothing wrong with your code. In struct newStruct you defined constructor with parameter that is called when you create instance of newStruct: newStruct abc = new newStruct(10);
In struct anotherStruct you also defined constructor with parameter, but this constructor is never called.
anotherStruct def; //here you create object def of type anotherStruct. no costructor is called
def.x = 250; // here you just assign value 250 to variable x, no constructor is called
def.method1(); //this writes 250 to output which is totally correct since you set x to 250 before
Compiler won't compile code if you do not set def.x.
I was probably wrong when I said there is default parameterless constructor. There is no default parameterless constructor at all and you can not declare your own.
|
|
|
|
|
Ok. Thanks for the clarification. But I think this proves there is nothing wrong declaring a value type stuct with a constructor - which obviously of no use and does nothing.
Regards,
Lenus.
|
|
|
|