|
what's wrong with this?
code of Class
class getUserName<br />
{<br />
private String _UserName;<br />
<br />
public String UserName<br />
{<br />
get<br />
{<br />
return this._UserName;<br />
}<br />
set<br />
{<br />
this._UserName = value;<br />
}<br />
}<br />
}
code of Button 1 in Form 1
i put the "myUsername" to Username inside the getUsername class so i can get the Username whereever i open a different form.
private void button1_Click(object sender, EventArgs e)<br />
{<br />
getUsername objgetUsername = new getUsername();<br />
<br />
objgetUsername.UserName = "myUsername";<br />
}
code of Button 2 in Form 2
here i will retrieve the myUsername to put it in the Messagebox to show the Username i used.
private void button2_Click(object sender, EventArgs e)<br />
{<br />
getUsername objgetUsername = new getUsername();<br />
<br />
MessageBox.Show(getUsername.UserName);<br />
}
my problem now is, I'm getting a null value in Form 2 Button 2 everytime i click the Button 2. Any help out there.
Thank You.
if(you type your code here) {
Messagebox.Show("You help me a lot!");
}
else {
You help me = null;
}
|
|
|
|
|
Simple - the two objects you create in the two methods are different.
Anyway, this is wrong on so many levels. Your classes should be nouns, not verbs. Also, you don't even need a new class to store the user name in this case. In your form, just declare private string _userName; Then, in your methods, you can read and modify _userName directly.
Cheers,
Vikram.
"I will put my new found knolage to good use" - Captain See Sharp.
"Every time Lotus Notes starts up, somewhere a puppy, a kitten, a lamb, and a baby seal are killed." - Gary Wheeler.
|
|
|
|
|
hi
i open my .mdb file from c# with system.diagonistics.proccess.start()
but i donot know how open it exclusive
i try to send the argument : /excl but it donot open exclusive
please help me
p00932004@yahoo.com
parastoo saadat
|
|
|
|
|
Hello!
You want to open it in MS ACCESS or open for data-access?
In second case, you have to connect to it using MS ACCESS driver/connection string. For connection-string visit ConnectionStrings.com.
Regards,
Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
hi all
iam having a grid in my application which has 4 columns of which 1 column i set visible=false.i want to bind the value of that column to the textbox.since the bound column is not visible the data is not coming in the textbox.can anyone tell me how to bind the data.
pintoo
|
|
|
|
|
Hi Chithra!
You must have some DataSource to bind a Grid. So directly set that column value to the TextBox.
Suppose you have DataTable as DataSource then try this.
DataTable dt = new DataTable();
if(dt!=null)
{
if(dt.Rows.Count>0)
{
TextBox1.Text = dt.Rows[0][4].ToString();
YourGrid.DataSource = dt;
YourGrid.DataBind();
}
}
I hope this will help you.
Regards..
"Save water,It's precious"
|
|
|
|
|
hi
thanx for the reply.but i have binded the data already.i want to retrieve the data from the gridview but not from the data table directly(data is present in the grid but the visible property is set to false.)i want to retrieve the data from the grid.
pintoo
|
|
|
|
|
Hi Chithra!
Where is your TextBox resides? Inner side or outer side of GridView?
"Save water,It's precious"
|
|
|
|
|
hey
i got it..the text box was outside the grid only..actually i used a html input field and made that field in the grid hidden..iam giving the code here which i used.
and to retrieve the value
txt1.Text = ((HtmlInputHidden)GvPromotion.Rows[e.NewEditIndex].FindControl("DescHiddenValue")).Value;
pintoo
|
|
|
|
|
hey
i got it..the text box was outside the grid only..actually i used a html input field and made that field in the grid hidden..iam giving the code here which i used.
and to retrieve the value
txt1.Text = ((HtmlInputHidden)GvPromotion.Rows[e.NewEditIndex].FindControl("DescHiddenValue")).Value;
anyway thanx for sparing your time..
pintoo
|
|
|
|
|
You are Welcome!......
"Save water,It's precious"
|
|
|
|
|
Hi,
I have developed a Windows Contol and now I want to add multi language support so that my control user (the developer) will be able to create a sattelite assembly and place the assembly to appropriate folder in his application. But I can I convert my control so that it can load string from sattelite assembly, moreover, how can I set the option to my control so that the language can be set or automatically set by the operating system ! 0r by the developer (manually). I searched in Google, but I am not getting any easy direction, all articles are talking about either how to create sattelite assembly or how to set different culture. But my problem is realted to Custom Control where I dont have headache of creating sattelite assemblies, rather I want to give the option to my control user to use sattelite assembly/
Please help.
|
|
|
|
|
I have an input class in my XNA game, and I call a method from that class to the main class, to exit the game.
(Basically)
class Game1 : XNA.blah,blah,blah<br />
{<br />
<br />
Input input;<br />
<br />
void Initialize()<br />
{<br />
input = new Input();<br />
}<br />
<br />
void Update(GameTime gameTime)<br />
{<br />
input.CheckInput();<br />
}<br />
}<br />
<br />
public class Input : Game1<br />
{<br />
public void CheckInput()<br />
{<br />
if (Keyboard.GetState().IsKeyDown(Keys.Escape))<br />
{<br />
this.Exit();<br />
}<br />
}<br />
}
*there's more code, but that's not the issue; regualr stuff it starts with
So, how would I make the game exit from a different class? Thanks.
- I love D-flat!
|
|
|
|
|
public class Game1{
private Input mInput;
public Game1(){
mInput = new Input(this);
}
}
public class Input{
private Game1 mGame;
public void CheckInput(){
mGame.Exit();
}
public Input(Game1 game){
mGame = game;
}
}
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
I am attempting to create a structure that I would like to call sizeof(myStruct) to return 16. However, when I attempt to make this call from code, I get the error,
'myStruct' does not have a predefined size, therefore sizeof can only be used
in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf) I searched online, and the only note that I found was someone who stated that, because the CLR determines the layout of the structure at runtime, the size of myStruct cannot be determined at compile time. Due to this comment, I thought that I could include the following attribute on my structure to solve this problem:
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 16)]
public struct myStruct : IEquatable<myStruct>, IComparable<myStruct>, IComparable {
...
} However, this results in the same error. There has to be a way for me to do this, as the built-in types int, float, etc. all allow this method call without throwing an exception. Another issue that I think is related is that I cannot declare a constant of type myStruct. If anyone has some insight into either of these problems, I would appreciate some help. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
So use an unsafe context, big deal.
|
|
|
|
|
Ok, but lets say that I am running it within a web service on a server that I don't control, and the server doesn't allow unsafe code to run?
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
In that case what would you do with sizeof?
|
|
|
|
|
I have a collection that I wrote that has a statement at the top as follows:
using BaseType = SomeStructTypeHere;
...
public class Foo : ... {
...
private const int c_Size = sizeof(SomeStructTypeHere) << 3;
private static readonly int c_Bits = MathExtension.Log2(c_Size);
...
} I did this for maintenence purposes, so I could modify the 'Foo' class as necessary to use one of any number of structures as the base type for the class (changing the base type only changes the hard limits on the class, but NOT its functionality). This class is being used in a web service, and therefore cannot use unsafe code, as I have explained. I would now like to use the 'Foo' class with my type as 'BaseType'. How can I go about doing this? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: cannot use unsafe code, as I have explained
Well, no you hadn't.
I think Mark's question still stands... what are you doing with the size?
|
|
|
|
|
PIEBALDconsult wrote:
Well, no you hadn't [stated that you cannot use unsafe code].
In my second post (in response to Mark), I said,
Ok, but lets say that I am running it within a web service on a
server that I don't control, and the server doesn't allow unsafe code to run? Perhaps I made it sound too much like a hypothetical, but it isn't. It the real-world, so unsafe is out of the question. What exactly am I using it for? Well, basically I need to know the size of the structure (call it 'X', in bits) so I can figure out some shift/mask values as follows:
1. I need to be able to shift something by all values < 'X'
for (byte i = X - 1; i >= 0; --i) {
...
long myValue = someValue << i;
...
}
2. I need to use the mask 'X' - 1 to get information from variables
long myValue = someValue & (X - 1);
3. I need to be able to shift something by log2('X')
long myValue = someValue << MathExtension.Log2(X); The previous three examples are riddled throughout my code, and X, Log2(X), and X-1 are all stored in constants within the class. Those constants are populated by making a call to the sizeof() method on the BaseType struct (declaration: "using BaseType = myStruct;"). How can I get this information without using unsafe context? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
We need to know what you are trying to achieve before we can make suggestions. What does this function on the webservice do?
|
|
|
|
|
Iterate the fields and sum their sizes?
Wouldn't you only need the size in an unsafe context anyway?
|
|
|
|
|
Please see my response to Mark for clarification on exactly what I am trying to do. However, iterating over the private members is far too much work for what I am attempting to do. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
say that within each egg carton, the ‘slot’ for each egg is given a number, just like we number arrays. We will also number the egg cartons themselves. So in the picture below, we see that egg carton #0 has 8 slots. Within egg carton #0, the slots are number 0, 1, 2, 3, 4, 5,6, and 7, just like the carton was an array. Another way to number the slots would be to use ‘global slot number’. This is what you’d get, if you started counting at the first slot in the first carton, and then kept counting when you moved on to the second carton, etc, etc. For example, “carton#0, slot#1” would be given the ‘global slot number’ of 1, since you start counting (at carton#0, slot#0) with 0, then count carton#0, slot#1 as ‘global 1’. When you run out space in the first carton (having reached ‘global 7’, at “carton#0, slot#7”), you go on to the second carton, and keep counting. So carton#1, slot#0 is actually ‘global slot number 8’. Carton #1, slot #5 is ‘global slot number 13’, and ‘global slot number 17’ really means carton #2, slot #1.
You need to fill in code, in program that is provided below, so that your program will ask the user for the ‘global slot number’ of a particular slot in a particular egg carton, and will then tell the user which carton, and which slot # with that carton, to put the egg.
|
|
|
|
|