|
i use list view that have control in this page
http://www.codeproject.com/cs/miscctrl/ListViewEmbeddedControls.asp
* if i have database with 3 recode ex:
------
field 1
------
5
7
8
-----
i want to add 3 row in the listView with first colum must be button(ClickMe)
the problem new
-----------------
1 - how i make my app when i click in the fisrt (ClickMe) button -> open new Form with 5 as parameter - > new Form(5);
and second button new Form(7);
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
enum MyTemp
{
cold = 0,
fp = 32
}
day1Miles.Text = textBox1.Text;
}
I get an error on 2 ( error says: } expected )
What am I missing in the concepts here? Why can't I define an enumerated constant at top of the button click? I can replace the enum statement with something like int cold = 0; and it works fine, so why can't I put an enum statement here?
For example this compiles without error:
private void button1_Click(object sender, EventArgs e)
{
int cold = 0;
day1Miles.Text = textBox1.Text;
}
-- modified at 12:49 Monday 14th August, 2006
|
|
|
|
|
Try defining the enum outside of your function.
|
|
|
|
|
Defining the enum outside the function is exactly what is needed, but I just don't understand why I would need to define the enum outside of the function.
|
|
|
|
|
Because it is pointless to define the enum in that scope. It wouuld only be valid for the scope of the function, and useless outside of it (you could not pass in a parameter of the enum type, nor return a an object of the eunum's type.
|
|
|
|
|
Thank-you for trying to help, but I am still confused....
Maybe here are some better examples of my dilema in undertanding where I can define an enum? I know I can make the example work by moving where the enum is defined, but I still do not understand why it needs to be moved. Why can't the enum constant be used just like a symbolic constant as my examples below demonstrate?
This does NOT work..... I would think it would, and still cannot understand why not.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
enum temps
{
cold = 0,
fp = 32
}
System.Console.WriteLine("freezing is {0}", (int)temps.fp);
}
}
}
But the following does compile...
namespace ConsoleApplication2
{
class Program
{
enum temps
{
cold = 0,
fp = 32
}
static void Main(string[] args)
{
System.Console.WriteLine("freezing is {0}", (int)temps.fp);
}
}
}
And this works, if ditch the idea of using an enum, and use named constants
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int cold = 0;
int fp = 32;
System.Console.WriteLine("freezing is {0}", cold);
}
}
}
|
|
|
|
|
Because the C# Language Specification says so. You can't do it because Enum's are an implementation of an abstract class (System.Enum), among other things. Since your really creating a concrete class by inheriting from System.Enum, you're bound by the rules of creating a new class. Classes can only be define at the Namespace and Class levels. You cannot define a class inside a method, so you can't define an Enum either.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
:-DAh makes sense now! Thank-you so much Dave and others too.
Just as a final blessing/followup. I thought I would try to show how classes cannot be defined within a method.
The example below does not compile - because you cannot define a class within a method ( you get the compile error: "} expected" on the line after the Main method) . And so the same problem would occur with the Enum - because you defining a class.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
class temps
{
public int cold;
public int fp;
public temps()
{
cold = 0;
fp = 32;
}
}
temps xTemps = new temps();
System.Console.WriteLine("freezing is {0}", xTemps.fp);
}
}
}
If you move the definition of the class where it can legally be defined (in namespace or within another class - in this case I moved it to the namespace)... then all works well.
namespace ConsoleApplication2
{
class temps
{
public int cold;
public int fp;
public temps()
{
cold = 0;
fp = 32;
}
}
class Program
{
static void Main(string[] args)
{
temps xTemps = new temps();
System.Console.WriteLine("freezing is {0}", xTemps.fp);
}
}
}
|
|
|
|
|
How can u get sytem properties like used memory, avilable free memmory total memory, processer spec etc using C#.net
|
|
|
|
|
See the System.Management classes.
|
|
|
|
|
How can i create OCX files in C#.Net... I want to use a custom control and make an OCX file from it(instead of dll).. can i?
|
|
|
|
|
No. You can, however, add the necessary registration code to your control, and then register if as a COM control and use it like an OCX..(it will need a strong name and must be installed to GAC)
|
|
|
|
|
can u tell me how to create it using C#.net?
please provide some help if u have.
|
|
|
|
|
Any .Net DLL can be used as a COM object. There are a number of articles like this one[^] on Code project.
|
|
|
|
|
i was asking can we create .ocx file for usercontrol as we does in vb 6.0?
|
|
|
|
|
You can create a user control as a dll and use it in non-C# code. see the article I linked (it discusses using the result in VB6), and search for COM interop. OCX is just a file extension It's the registry entries that matter.
|
|
|
|
|
Right-click on your dll project in the Solution Explorer window within Visual Studio. Go to the "Build" tab. There is a checkbox on that page for "Register for COM Interop". Check that, and your .dll will automatically be registered for COM interop, meaning you could use it from COM.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: And in this corner, the Party of Allah
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
|
|
Hi
I wanna ask about "How Can I get Keyboard Layout?", It may be easy quesion but I stuck on it.
3doorsdown
Regards,
Hisham Galal <me4webby@yahoo.com>
|
|
|
|
|
|
Hi,
I ask about the current language of the keyboard
Regards,
Hisham Galal <me4webby@yahoo.com>
|
|
|
|
|
hello evrey one i put panel control on form and i want when mouse move on panel draw with mouse moving using GDi i do thing like (paint) in windows
|
|
|
|
|
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawLine(Pens.Red, 0, 0, Width, Height);
}
|
|
|
|
|
Hi..
I have made a custom template that derives from ITemplate.
I have also create a class that inherits from INaming container.
For some reason i can not get the INaming container to work with my custom template. In order to implement the INaming container one must have a property that returns an ITemplate.
Why can i not return my custom Template the derives from ITemplate?
here is some of my code:
----
[ParseChildren(true)]
[PersistChildren(false)]
[ToolboxData("<{0}:HoverCalendar runat=server>")]
public class HoverCalendar : WebControl, INamingContainer
{
private ITemplate _itemTemplate;
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate ItemTemplate
{
get { return _itemTemplate; }
set { _itemTemplate = value; }
}
protected override void CreateChildControls()
{
Controls.Clear();
HtmlGenericControl container = new HtmlGenericControl("div");
if (ItemTemplate != null)
{ ItemTemplate.InstantiateIn(container); }
Controls.Add(container);
base.CreateChildControls();
}
}
*** this works fine; however, how do i use my ( the one below for example ) template?
----
public class myItemplate_1 : ITemplate
{
static int itemcount = 0;
ListItemType templateType;
public myItemplate_1(ListItemType type)
{
templateType = type;
}
public void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();
switch (templateType)
{
case ListItemType.Header:
lc.Text = "<TABLE border=1><TR><TH>Items</TH></TR>";
break;
case ListItemType.Item:
lc.Text = "<TR><TD>Item number: " + itemcount.ToString() +
"</TD></TR>";
break;
case ListItemType.AlternatingItem:
lc.Text = "<TR><TD bgcolor=lightblue>Item number: " +
itemcount.ToString() + "</TD></TR>";
break;
case ListItemType.Footer:
lc.Text = "</TABLE>";
break;
}
container.Controls.Add(lc);
itemcount += 1;
}
}
thanks
erik
|
|
|
|