|
There are several ways to go about it. One is to use panels like you are now, as you noted it is clumsy to work with. Another way is to base your wizard on the TabControl, then you can create each of your steps as a tab on the control.
Yet another way (and the way *plug plug* my wizard framework[^] uses) is based on User Controls, where each step is a separate User Control. I have a specialized form that handles all of the work of switching in and out, you just need to handle a few events to tell it how it should work.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
|
Hi.
im am a newbie with c#. i had created an object in one form (e.g. Form1) and i need its values from Form2. i also need the possibility to change my object's values from Form2.
how do i do that ???
Thank ....
Bob.
|
|
|
|
|
That would depend entirely on exactly what you are trying to do. If the Object is a Control you have added to the form and you know the objects name. You can access the Controls properties and methods via
for(int i = 0; i == this.ParentForm.Controls.Count-1;i += 1){
if(this.ParentForm.Controls[i].Name == "ControlName"){
}
}
However, if you need to access varibles only, you should create a static class similar to this.
using System;
namespace staticTest
{
public class Setting{
public static String[] test = new String[10];
public static int[] testInt = new int[10];
static Setting(){
}
}
}
|
|
|
|
|
|
That depends on how you are using the datagrid. A universal way is to change the ColumnStyle for the correct column. This may not be obvious if you are letting the DataGrid auto-generate the columns for you, but should work.
A couple specific cases:
If you are binding to a DataSet/DataTable then you can set the ReadOnly property on the column in the DataTable.
If you bind to a custom class, columns for properties without a set method will default to ReadOnly (probably not able to change it either...I would hope not anyway )
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi all,
I've got a class that holds lots of different public string members:
public class AuthorData
{
public string Name;
public string Addr1;
public string Addr2;
} I'd like to be able to add references to these strings to a member string[] variable, so that I can perform operations on all of them at once with a foreach loop:
public class AuthorData
{
public string Name;
public string Addr1;
public string Addr2;
public string[] allStringMembers;
} Problem is, I can't figure out how to construct the array so that it references the string variables, rather than a copy of them. All of my attempts so far lead to an array where changes to the array contents /don't/ affect the original string members. What I need is the equivelant of a 'pointer' to the string members, but I can't figure out how to get one. I've tried messing around with String::Clone(), and String.Intern(), but can't seem to get a reference.
As a side-issue, it would be nice to add another layer of indirection to the array (in effect an array of pointers to pointers to the string members), as this would allow me to initialise the array in AuthorData's constructor. A single layer of indirection wouldn't allow this, as the string[] would simply contain null's - the member string vars are assigned null initially. If I can't do this, I think I'd have to make allStringMembers a readonly property that dynamically creates the array every time it is accessed.
I hope that all makes sense, if examples of my (failed) attempts would be helpful, please say so.
TIA,
Pete
|
|
|
|
|
I believe I would expose the string members via properties that return an array element:
public class AuthorData{
public string[] allStringMembers;
...
public string Name
{
get{
return allStringMembers[Name];
}
}
}
Instead of exposing an array, consider implementing IEnumerable, then iterate on the object itself:
public class AuthorData : IEnumerable{
private string[] allStringMembers;
...
public string Name
{
get{
return allStringMembers[Name];
}
}
...
public IEnumerator GetEnumerator(){
...
}
}
And use it thus:
AuthorData aData = new AuthorData;
foreach (string s in aData)
{
...
}
As an aside, it would be interesting to know what kind of process you wish to perform on all members (if you don't mind sharing).
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Using properties instead of string vars seems sensible to me. Unfortunately it could be tricky, this class is being XML Serialised/Deserialed as part of a Web Service method. I'll have to do some experimentation.
Although IEnumerable is a nice idea I think it's a little over-kill for this class, it's just a simple way for me to hold data supplied by a Web Service consumer. The processing is simply Trim()ing the strings, and setting them to null if they're empty, prior to storing them in a database.
Thanks for the help Jim, I'll keep you informed on my progress....
Pete
|
|
|
|
|
May I suggest then moving the string manipulation code into the class and scrubbing the enumeration idea. The Get property methods could perform this process.
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Hmm, yeah that seems sensible.
I'd still like to have the array though, as I may add more string members at a later stage and I like the idea that this would only break one bit of code...
|
|
|
|
|
Hmm,
Well I've encountered my first problem - compiler error CS0206: A property or indexer may not be passed as an out or ref parameter
Some of the methods that work on the member strings need a ref string parameter, so that they can modify the actual string rather than a copy.
I think I should be able to design my way around this though...
|
|
|
|
|
OK, that's fixed.
I'm very impressed that changing the members to properties had no effect on the XML Serialisation (at least, none that I can tell - all my tests still run 100%).
So it should be pretty simple now to move the processing functionality into the class (actually i'll probably make a generic DataInterface class that Trim()s it's string members and inherit from that).
Thanks for the help!
|
|
|
|
|
moredip wrote:
I'd like to be able to add references to these strings to a member string[] variable, so that I can perform operations on all of them at once with a foreach loop:
Let the class implement IEnumerable. Arged wrote all the code, it doesnt work!!!
New option HashTable make those fields rather properties referencing objects in a hashtable with the method name as the key. Use reflection to get /set the value.
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Again, although those are both sensible ideas, they are a bit heavy-weight for my little class. I don't really need that much functionality, at least not right now.
Being a lazy developer I like to do the least amount of work possible
|
|
|
|
|
moredip wrote:
they are a bit heavy-weight for my little class
Not heavy at all, you can provided a base class that does the enumeration, indexing etc, all via reflection. Meaning every single class have this behaviour. If this is something in SQL your are doing, I have some neat code.
moredip wrote:
Being a lazy developer I like to do the least amount of work possible
You are obviously not "economizing" (my personal word for laziness) enough. I have used the same approach to make persistant object classes. All hidden to the user. Have a look at my DBHelper article for real "lean" code. Its astonishing what can be done with so little (or just putting the pieces correctly in place).
Cheers
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
Just had a look at your article, that's a nice tool. It's not really needed for what I'm doing (trying to avoid SPs), but thanks anyway.
When I said 'heavy-weight' I was kind of referring to functionality that was superfluous, rather than a lot of extra coding - although that was a factor
The classes I'm talking about are really just a handy way for me to exchange data with consumers without having to mess with DataSets, and I want to keep them as simple as possible (KISS).
Again, thanks for the help,
Pete
|
|
|
|
|
moredip wrote:
The classes I'm talking about are really just a handy way for me to exchange data with consumers without having to mess with DataSets, and I want to keep them as simple as possible (KISS).
In that case, why not just make a wrapper class to handle those "extra" functions?
MyDUMeter: a .NET DUMeter clone "Thats like saying "hahahaha he doesnt know the difference between a cyberneticradioactivenuclothermolopticdimswitch and a biocontainingspherogramotron", but with words you have really never heard of."
|
|
|
|
|
That's pretty much what this class is, a wrapper around the raw data. It does just enough for my purposes - which at the moment is just some simple pre-processing of supplied strings.
|
|
|
|
|
I'm trying to complete Chris Maunder's article for creating "your first web service" http://codeproject.com/cs/webservices/myservice.asp and am having a few problems. I've got visual studio.net installed but I don't have the option of creating a C# web service from the new project menu. The options I do have are as follows: Windows App, Class Library, Windows Control Library, ASP.Net Web App, ASP.Net Web Servce, Web Control Library, Console App, Windows Service, Empty Project, Empty Web Project, and New Project in Existing Folder. Is there something I can do to add or turn on the options I'm missing to be able to create a C# web service?
Thanks, Doug
|
|
|
|
|
Manster wrote:
ASP.Net Web Servce
that is the one, if you want to create web service, the default options spits the code for a 'hello world' web service, its commented by default.
If you are thinking about consuming webservice, you will have to add a web-reference (right click on the web reference tab and add the url for the web service you want to consume).
Hope this helps.
Cheers
Kannan
|
|
|
|
|
Is there an alternative way to create shortcuts in C# other than using the Wshell? Because everytime i include my app and distribute it to others, some people don't have the wscript.exe and even if they DID install it, they get this kind of error : "IWshShell3 failed". Are there any workarounds to this?
|
|
|
|
|
You can use the COM ShellLinkObject to create shortcuts, and this only requires shell32.dll.
In an ideal world, things would be simple and you would just have to add a reference to shell32 in the VS.NET IDE, then start playing with the objects and interfaces.
Unfortunately, the actual IShellLink interface is not declared in the shell32 namespace. You'll find ShellLinkObject and ShellLinkObjectClass but they are worthless.
That's somewhat tough since you have to do the interop yourself, ie declare COM signatures. Here is how it goes :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IShellLinkA
{
void SetPath(string path);
void SetDescription(string path);
void Save(string where);
...
}
ShellLink c = new ShellLink();
IShellLinkA i = (IShellLinkA) c;
i.SetPath("ert");
...
That's just the begin of the code.
Be sure to read this reference MS article[^] (WIN32 C/C++ audience though).
|
|
|
|
|
i put in this :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class ShellLink
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface IShellLinkA // Cannot list any base interfaces here
{
void SetPath(string path);
void SetDescription(string path);
void SetIconLocation(string path, int index);
void Save(string where);
void SetWorkingDirectory(string path);
}
and called this:
ShellLink c = new ShellLink();
IShellLinkA i = (IShellLinkA) c;
i.SetPath(@"c:\test.txt");
i.Save(@"c:\test.lnk");
but it doesn't work (the shortcut doesn't appear). And i don't quite understand some of the stuff/code on the link you gave me (mainly because it's in C/C++). Any help would be greatly appreciated.
|
|
|
|
|
In my code snippet, IShellLink was declared as a dual interface, although, after I have double checked it, it's only a IUnknown interface.
Here is the right declaration and code :
[ComImport, Guid("00021401-0000-0000-C000-000000000046")]
class SH
{
}
[Guid("000214ee-0000-0000-c000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IShellLinkA
{
void GetPath(string pszFile,
int cchMaxPath,
IntPtr pfd,
int fFlags);
void GetIDList(IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription(string pszName,
int cchMaxName);
void SetDescription(string pszName);
void GetWorkingDirectory(string pszDir,
int cchMaxPath);
void SetWorkingDirectory(string pszDir);
void GetArguments(string pszArgs, int cchMaxPath);
void SetArguments(string pszArgs);
IntPtr GetHotkey();
void SetHotkey(int wHotkey);
void Resolve(IntPtr hwnd,
int fFlags);
void SetPath(string pszFile);
}
SH c = new SH();
IShellLinkA i = (IShellLinkA) c;
...
UCOMIPersistFile p = (UCOMIPersistFile) i;
p.Save(@"c:\mylink.lnk",false);
|
|
|
|