|
|
Hi everybody,
I have a big problem with listbox . I created a user control which contains two listboxes and two buttons to permit switch a single or multiple items from listbox1 to listbox2.
When I click into vertical scrollbar (not on the track button but inside the scrollbar, it moves itself to place the selected item on bottom of the active listbox . My problem is that play only at the first time that I use the listbox (after the form load event)
I hope have clearly explain my problem and hope someone help me.
PLEASE.......... HELP ME !!!!!!!!!
Thanks for help.
X-TroLL
|
|
|
|
|
|
hi to all,
how can i put a link label in a listview cell ? and how to fire an event when i click the data in the cell ?
best regards and thanks in advance
fady
|
|
|
|
|
I have the following within my myWall Class:
<br />
private Point _wallLocation = null;<br />
<br />
public myWall(Point newLocation)<br />
{<br />
this._wallLocation = newLocation;<br />
}<br />
This returns a compile time error of:
Cannot convert null to 'System.Drawing.Point' because it is a value type
So I have to use one of the following two options and either make it:
<br />
private Point _wallLocation;<br />
or
<br />
private Point _wallLocation = new Point(1,1);<br />
I am new to C# (< 5 days) with a C background, so to me the first option isn't good because I have an unassigned variable kicking around. The second option isn't any good because I am wasting resources allocating a Point that I will never use.
What is the best way to allocate a ValueType that has nothing stored in it if I can't null it?
If I use the first example does that mean that the Point is actually allocated? If so does it have random data in it? This would imply that the two options above cost exactly the same processor wise.
Thanks.
-Rowan
|
|
|
|
|
Look at it this way.. Whenever you have a value type, like int, double, ..., or any struct (like the Point in your code), treat the thing as you would a normal variable which is not dynamically allocated. The value types are not allocated on the heap, as are all objects of classes in C#. But they are placed on the stack.
Assigning null to a reference object (an object of a class) derefences the memory, so that the gc can clean up the mem when there are no other reference to that particular memory. Since value types are not on the heap no cleaning up is necessary (they go out of scope).
Put it otherwise all objects of classes are pointers to these object, all objects of value types are just that the object itself.
You will need to initialize your Point with a default value if the (0,0)(which is the default) is not to your liking.
I hope this sheds some light to the issue for you.
Greetings
Davy
|
|
|
|
|
Hi,
Why do you not use a property ?
<br />
private Point _wallLocation;<br />
public Point WallLocation<br />
{<br />
get{return _wallLocation;}<br />
set{_wallLocation=value;}<br />
}<br />
<br />
And into your class constructor<br />
public Constructor()<br />
{<br />
_wallLocation = new Point(0, 0);<br />
}<br />
I think that the best solution because the Nullable type is not implemented in the .Net Framework 1.X but in 2.0 it does .
In .Net programming, you must allocate all variables having ValueType type.
I hope that help you
X-TroLL
|
|
|
|
|
-Rowan- wrote: the first option isn't good because I have an unassigned variable kicking around.
I don't think you need to bother about that - whenever you try to use something like _wallLocation.x , the compiler flags it as an error, so you won't get any nasty runtime surprises.
-Rowan- wrote: If I use the first example does that mean that the Point is actually allocated?
I'm a tyro myself, but I think the answer is No.
HTH.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
Vikram A Punathambekar wrote: I'm a tyro myself, but I think the answer is No.
Actually, yes. This piece of code will compile and run fine
struct X
{
int y;
}
void SomeMethod()
{
X x;
x.y = 100;
Console.WriteLine(x.y);
}
The new operator for structs is only to initialize the struct's members to 0/null. Instead of that, if you take care of the initialization before using the struct, it'll work just fine.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You're right, Senthil.
I was trying to print the member's value directly instead of assigning a value, and got an error. I assumed that it was because the variable was not created.
Cheers,
Vikram. "When I read in books about a "base class", I figured this was the class that was at the bottom of the inheritence tree. It's the "base", right? Like the base of a pyramid." - Marc Clifton.
|
|
|
|
|
A value type is always allocated whenever it is in scope, that means that it always has a value. If you haven't assigned a value to it, the value is undefined (e.g. unknown or "random").
Most of the time, though, the compiler won't let you use a variable that has an undefined value.
The Point class has an IsEmpty property and an Empty field that you can use to specify an unassigned value:
private Point _wallLocation = Point.Empty;
The _wallLocation.IsEmpty property returns true when the location is undefined.
---
b { font-weight: normal; }
|
|
|
|
|
-Rowan- wrote: What is the best way to allocate a ValueType that has nothing stored in it if I can't null it?
If you're the author of the type, you could have a special static property to do that, something like
struct MyStruct
{
static MyStruct Empty
{
return new MyStruct(<Some Invalid Value>);
}
}
-Rowan- wrote: If I use the first example does that mean that the Point is actually allocated? If so does it have random data in it? This would imply that the two options above cost exactly the same processor wise.
Almost but not quite true. Your first example does result in a stack allocation. The compiler forces you to initialize all fields before using the instance, so you won't run into random data.
The second line of code causes the compiler to emit a .initobj IL instruction, which results in all fields in the struct being initialized to their default values.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi.
I have a website where i want to pass some values from one site to another.
my problem is that i store the values in an array, but the length must not be longer or shorter than needed.
example:
http://mywebsite.com/graph.aspx?item1=cat&item2=horse&item3=dog
string item1 = Page.Request.Params["item1"].ToString();
string item2 = Page.Request.Params["item2"].ToString();
string[] labels = { item1, item2, item3 };
but if the user inserts "&item4=cow" into the url, then it would give an error.
i need the labels array to extend so that it gets item4 if item4 exsist in the URL.
I new to this, please help me.
-- modified at 5:26 Wednesday 14th December, 2005
|
|
|
|
|
You can't change the size of an array, so you either have to determine how many items you need before you create the array, or use a collection (like ArrayList or Hashtable).
---
b { font-weight: normal; }
|
|
|
|
|
Or......
At startup allocate one receive buffer that will accomodate that largest message you expect (plus a little overhead is OK too). Then on your message received function, New a temp buffer of the exact size of the received message and then Array.Copy the new message into a buf, then use it however you wish.
Mike Luster
|
|
|
|
|
in a Extended column, if the entry is invalid i want to keep focus, but when user presses direction key i lose focus.
2. Problem is, in a datagrid which all columns are extended xolumns, when the user press tab key, cursor moves 2 cells.
|
|
|
|
|
I extend DataGridTextBoxColumn class as DataGridDateTimeExtendedColumn class
I use this class for date entries. When user pushes to 3rd number -for month- i automatically add string a point for separator. Bur whenever adds something to entry , Commit event raised so it doesnt work properly. What can be problem?
All i want is a control which user can input in format "dd.mm.yyyy"
|
|
|
|
|
hi.
I need a sample code to use Add.parameters of command object for SQLClient, please.
Best wishes
|
|
|
|
|
Hello
Ok, Lets imagine we have a Table in sqlServer with these fields:
id (int) , name (nVarChar) , sex (bit)
I show you examples about UPDATE Query with Parameters :
strSQLUpdate = "UPDATE Table SET name=@name,sex=@sex WHERE idu=@idu" ;<br />
cmd = new SqlCommand(strSQLUpdate,Connection) ;<br />
cmd.Parameters.Add ("@id",SqlDbType.Int, 4,"id") ;<br />
cmd.Parameters ["@id"].Value = txtID.Text ;<br />
cmd.Parameters.Add ("@name",SqlDbType.NVarChar, 20,"name") ;<br />
cmd.Parameters ["@name"].Value = txtUsername.Text ;<br />
cmd.Parameters.Add ("@sex",SqlDbType.Bit, 1,"sex") ;<br />
cmd.Parameters ["@sex"].Value = radioButton.Value ;<br />
cmd.ExecuteNonQuery() ;
If you need more codes please alert me and wait 5 hours.
Bye.
|
|
|
|
|
And same sample code using oledb & odbc, please?
Best wishes
|
|
|
|
|
Hi Friends,
I am developing application based on .net Remoting. In my client application i have accessed the remote object by Activator.GetObject function. In this GetObject function, i have passed the second argument as URL, like "tcp://localhost:8384/Container". From my client program how can i validate this URL ? i.e., before using this url i need to identify whether any service is published on this URL or not. Please help me to solve this issue.
Regards,
Prakash.
A Journey of thousand miles must begin with a single step.
|
|
|
|
|
Hi friends,
Am having a grid with a TextBoxColumn which has a combobox...
What eventhandler should be used if ,after selecting the item from the combo,i use the up and down arrow keys to move up and down the rows of the grid.?
Combobox's Leave event is getting fired when i use tab key or mouse alone...
Need urgent help..plz...
Thanx...
|
|
|
|
|
Hi friends,
I tried myself and got the solution....
if anyone needs the solution, ask me.....
|
|
|
|
|
I'm having the source code of the web site with streams,response and request.Then i must find the links in sourcecode.i have got a regex that email finds.
string mail=@"(href=)((')|(""))(mailto (?<mail>(.*))((')|(""))";
So i need another regex that about link.How can i learn the regex writing regulation in C# or how can i write linkregex.
i need have only the website url on this code.
|
|
|
|
|
Hi!
If you want to learn how to use RegEx, just search in google. Helpful is one of the regex trainer which let you test your regex search-string before you use it.
But here is an example to catch URLs:
// Clear old data in listboxes
listBox1.Items.Clear();
listBox2.Items.Clear();
// example HTML document
string lsCode = "<HTML><BODY>test1<BR><A HREF='LinkURL1'>Link1</A><BR>test2<BR>" +
"<A HREF='LinkURL2'>Link2</A><BR></BODY></HTML>";
// Regex object to search
System.Text.RegularExpressions.Regex loCheck = null;
// search-string for regex (improtant: ignorecase-option)
loCheck = new System.Text.RegularExpressions.Regex("href=[\"']{0,1}([^\"'> ]*)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.MatchCollection loLinks = loCheck.Matches(lsCode);
// write every value in the list
foreach (System.Text.RegularExpressions.Match loResult in loLinks)
{
// loResult.Groups[0].Value = "HREF='LinkURL1"
// loResult.Groups[1].Value = "LinkURL1"
listBox1.Items.Add(loResult.Groups[1].Value.ToString());
}
// search-string for regex (improtant: ignorecase-option)
loCheck = new System.Text.RegularExpressions.Regex("[\"']>{0,1}>([^<]*)</A>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.MatchCollection loLinksText = loCheck.Matches(lsCode);
// write every value in the list
foreach (System.Text.RegularExpressions.Match loResult in loLinksText)
{
// loResult.Groups[0].Value = "'>Link1</A>"
// loResult.Groups[1].Value = "Link1"
listBox2.Items.Add(loResult.Groups[1].Value.ToString());
}
In listBox1, all Link addresses will be added. In listBox2, all link text (within <A HREF>???</A>) will be added.
Marcel Erz
|
|
|
|