|
Thank you,
i think i try it with the tag property
greetings
mike
|
|
|
|
|
I have a ComboBox and I’m giving it a Class cCompany not just a string.
public class cCompany
{
public string sz_Name;
public string sz_Address;
public cCompany(string Name, string Address)
{
sz_Name = Name;
sz_Address = Address;
}
public cCompany(cCompany obj)
{
sz_Name=obj.sz_Name;
sz_Address = obj.sz_Address;
}
public override string ToString()
{
return sz_Name;
}
}
In the ComboBox one types the name of the company and there is a TextBox where one types the address.
My way of thinking is that this line
this.cbToCompany.Items[index].sz_Address=this.tbToAddress.Text;
should compile but the .sz_Address gives this error:
'object' does not contain a definition for 'sz_Address'
I’m a beginner C# programmer and until now I’ve found the language very intuitive. Pleas help.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
|
|
|
|
|
See u have sz_Address in the class onl. But that property not exist in the combobox item[index] property.
U can find it out more easyly. After tying this.cbToCompany.Items[index] whne u will press "." after that did u find sz_Address. if u'r finding it is ok. If not place
this.cbToCompany.Items[index].add=this.tbToAddress.Text;
i think this may work out.
Bye
Arun Kumar Sabat
|
|
|
|
|
The ComboBox.Items property is a ObjectCollection, so that this code snippet this.cbToCompany.Items[index] returns an instance of type Object. To use it the way you want you'll have to cast the instance first:
( (cCompany) this.cbToCompany.Items[index]).sz_Address=this.tbToAddress.Text;
If you use this be sure your ComboBox contains only instances of type cCompany cause otherwise an exception will be raised.
www.troschuetz.de
|
|
|
|
|
Thanks,
That worked perfactly!
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
12029 45 Street N.W.
Edmonton, Alberta, Canada T5W 2T7
Res. Ph: (780) 695.5589
Email: rhahn82@telus.net
|
|
|
|
|
Hi~
Can I export a class written in C++ in dll to C#? That means can I use the class C++ dll to declare objects in C#?
Thanks
|
|
|
|
|
Yes you can. This[^] should get you up to speed.
Paul Lyons, CCPL Certified Code Project Lurker
|
|
|
|
|
Actually it won't. Interop'ing native classes (i.e., not COM components) is not covered in the tutorial. There is some vague documentation in the CallingConvention enumeration, though.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
Next question is:
I found some stuff to enumerate the GAC, but what I want is something that looks more like VS's Add Reference dialog. There are two interesting things going on in this list:
1. It shows the path to the installed assembly, not the GAC path
2. It only shows assemblies relevant to the current compiler version.
How the heck does it do that? I've looked around for a couple months, off and on, and have never found the answer!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
It has nothing to do with the GAC. See the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
See the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\.NETFramework\AssemblyFolders.
I hope I'm not asking a really dumb question here--I have entries in that registry key, but there's no "data"--only folders with the names of the assemblies.
So, the question is, how do I take that information and obtain the actual assembly path?
Thanks!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Enumerate the sub-keys and grab the default value of each sub-key. Enumerate each directory to load the assemblies:
using System;
using System.IO;
using Microsoft.Win32;
class Test
{
static void Main()
{
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(
@"Software\Microsoft\.NETFramework\AssemblyFolders"))
{
foreach (string key in rk.GetSubKeyNames())
{
using (RegistryKey af = rk.OpenSubKey(key))
{
string dir = (string)af.GetValue(null);
if (Directory.Exists(dir))
{
Console.WriteLine("Enumerating \"{0}\"...", dir);
foreach (string file in Directory.GetFiles(dir, "*.dll"))
{
Console.WriteLine(file);
}
Console.WriteLine();
}
}
}
}
}
} If you want to check the version of the runtime the assembly uses, you could load it and see which version of mscorlib.dll is required. If this application will be running for a while (like Visual Studio), then you should consider creating a new AppDomain to do this since you cannot unload assemblies and don't want to have all those assemblies loaded for no reason.
Instead of loading the assemblies, you could also load the PE/COFF images and determine the information yourself. You could use IL Reader[^] (from Lutz Roeder, creator of .NET Reflector) to inflect what that could be and not load the assembly into an AppDomain at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Oh God, I'm an idiot. I had the data name column set so wide on my registry view that I didn't even see that the default value had any content.
Major embarassment here.
Thanks for the other feedback regarding figuring out what version of mscorlib.dll is required. That's definitely something I didn't realize!
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
Is it possible for a dll to call dll? What I'm doing is creating few dll, along with one standard.dll. For example, those dlls (111.dll, 222.dll, 333.dll, 444.dll, 555.dll) would call a single function from standards.dll. So that the function in standard.dll would be consistent with those 5 dlls. It will save time rather than having to recompile all of those 5 dlls after revising the standard.dll.
I have created the application which passes the string variable over to the dll then one of those 5 dll would be used (depending on the data). I hope that I have explained clearly.
I've been using Visual.Net C# language to do this. I am able to communicate with one of those 5 dlls, but unsure how to do this to have one of 5 dlls to communicate with standards.dll. I am also hoping to have standard.dll to be separate from those 5 (not to be built in but separeate.)
|
|
|
|
|
DLLs don't "call" other DLLs, but they do reference them. Assemblies can reference each other, and you can even have circular references (it's very tricky, though, and requires pretty good knowledge of the DLLs - but Types can't be circular), but not in Visual Studio .NET.
Your types in other DLLs (assemblies are what they actually are in .NET) must be public in order for Types in other assemblies to use them. This is no different than when you reference assemblies from the Base Class Library (BCL), like System.Windows.Forms.Form for Windows Forms, or System.Web.UI.WebControls.Control for ASP.NET web controls.
Using VS.NET, you can add references to .NET assemblies, COM libraries, and even other projects in the same solution. Right-click on your project and select Add Reference. Use project references when possible (with multi-project solutions) to establish build dependencies.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
The poor guy is probably trying to do some type of plugin architecture... maybe couldn't express himself correctly.
In that case he can start digging through Reflections
|
|
|
|
|
I've got it!
I've used the dll's (not the standards.dll) to be called by late binding of dll's (see sample code below
----
String PassToDll("FFEEFF1A");
String path = "abc.dll";
Assembly a = Assembly.LoadFrom(path);
Type mm = a.GetType("abc");
object o = Activator.CreateInstance(mm);
object [] par = new object[] {PassToDll};
edtDllResult.Text = mm.InvokeMember("InterpretCrumData", BindingFlags.Default | BindingFlags.InvokeMethod, null, o, par).ToString();
----
then I created abc.dll by creating a new library. I added the reference for Standards.dll.
then sample code in abc.dll
----
using System;
using Standards_Dll;
//namespace abc_Dll
//{
///
/// Summary description for Class1.
///
public class abc
{
public abc()
{ // TODO: Add constructor logic here // }
public int InterpretCrumData(string readtext)
{
// snip code
return (<variable>);
}
}
// }
----
So now I am able to make more dll's for this.
|
|
|
|
|
hey all,
I'm somewhat new to C# programming. Basically I want to send the current day that the program is executed on (Monday, Tues, Etc.) to a variable, and then to a text box (textBox1). here is what I have so far to run when the form loads.
if (day = DateTime.Today.DayOfWeek.Equals(Monday))<br />
this.textBox1.Text = "It is Monday!";<br />
else<br />
{<br />
}
I also added the namespace (I think its called)
private System.DateTime day;
so what's wrong with the code? any help would be awesome.
I know I have a lot of learning ahead, so don't worry about the criticisms
happy programming,
Stephen
|
|
|
|
|
I think what you want is:
if (DateTime.Today.DayOfWeek==DayOfWeek.Monday)
{
...
}
There's no reason to use "Equals", but if you want to, you probably have to say "Equals(DayOfWeek.Monday)" to properly reference the enumerator.
Also, the "day=" assignment doesn't make any sense. Is "day" a boolean? Because that's what the Equals returns.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
awesome, thanks a lot for the help.
-Stephen
|
|
|
|
|
just a thought (not at a computer with a programming environment atm)
Does this work:
<br />
this.textBox1.Text = "It is " + DateTime.Today.DayOfWeek.ToString() + "!";<br />
(You'll probably have to fiddle syntax, as that's just off the top of my head)
I've noticed all these ToString members everywhere - dunno if it'd work properly with an enum like that, but it seems to be what it's intended for!
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
I'm trying to use a animated GIF file on my splash screen. The GIF is placed inside of a picture box. The picture shows fine but the animation doesn't work. When I use the GIF in any other form the animation works. It just won't work on the splash screen. Any Ideas?
|
|
|
|
|
There could be several things wrong, but you need to be more specific about how you're dealing with your splash screen, since it could be implemented in countless different ways.
The important thing is that you always modify a control - like change the PictureBox.Image property if that's what you're doing - in the thread on which the control was created. You can do this using the InvokeRequired property and the Invoke method, both of which include an example of using them (they're defined by the Control class and, thus, inheritted by every derivative class).
If you're doing this on a timer's event handler (like the System.Windows.Forms.Timer component), than you are doing this in a different thread and the results are undefined.
This is, most likely, the problem you're having.
Now, if you mean the GIF is animated and your PictureBox isn't animating it, please post some additional code to help us understand how you're using the control.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
hello techies,
I written a C# application which executes few stored procedures against the database(MSsql 7.0) .While executing stored procs thru my appln, sometimes it throws sql exception saying "Time expired when running the scripts". But it happens only 2 out of every 10 test runs..
Is there a way to overcome this problem
rgds,
jagan
ps; I donot have that many connections to SQL server as well.
|
|
|
|