|
|
|
i have the folowing class:
class MyClass<br />
{<br />
public MyClass(string str)<br />
{<br />
Str = str;<br />
}<br />
<br />
public string Str;<br />
<br />
public override string ToString()<br />
{<br />
return Str;<br />
}<br />
}
now lets add some items to a ComboBox:
comboBox1.Items.Add(new MyClass("aaa"));<br />
comboBox1.Items.Add(new MyClass("bbb"));<br />
comboBox1.Items.Add(new MyClass("ccc"));
and now....
suppose that i want to change the first item Str member to "ddd":
the following line doesn't work:
((MyClass)comboBox1.Items[0]).Str = "ddd";
But the following will work:
comboBox1.Items[0] = new MyClass("ddd");
It seems that a copy of the item is returned from the object collection in the ComboBox.
Does anyone know how it is possible to change the item directly without replacing it?
Thanks in advanced, Ilan
|
|
|
|
|
Have you tried invalidating the combobox after you change the Str property?
I've just re-tried this code out and it worked as you want and as I expected.
Sorry, problem with your dev system not .NET
Ed
|
|
|
|
|
I am sorry - it doesn't work even if i validating the combo box:
here is the complete code again:
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
comboBox1.Items.Add(new MyClass("aaa"));<br />
comboBox1.Items.Add(new MyClass("bbb"));<br />
comboBox1.Items.Add(new MyClass("ccc"));<br />
<br />
((MyClass)comboBox1.Items[0]).Str = "ddd";
comboBox1.Invalidate();<br />
}<br />
...<br />
...<br />
...<br />
class MyClass<br />
{<br />
public MyClass(string str)<br />
{<br />
Str = str;<br />
}<br />
<br />
public string Str;<br />
<br />
public override string ToString()<br />
{<br />
return Str;<br />
}<br />
}<br />
<br />
Well, i am usin VS2005.
|
|
|
|
|
That doesn't work, because the combobox is already in the state of invalid when you try to invalidate it. The combobox has already detected that you have added items to it, and is only waiting for your code to end to redraw itself. When the items were added the ToString method was called to get their values, and those are the values that will be used to redraw the combobox. The combobox hasn't detected that you have changed the underlying data of one of the items since then.
If you change the item and invalidate the combobox once the combobox has been drawn, for an example on the click event of a button, it will work.
---
b { font-weight: normal; }
|
|
|
|
|
I am sorry - i tried and tried and it doesn't work, pay attention that the following WILL work fine:
<br />
comboBox1.Items.Add(new MyClass("aaa"));<br />
comboBox1.Items.Add(new MyClass("bbb"));<br />
comboBox1.Items.Add(new MyClass("ccc"));<br />
<br />
((MyClass)comboBox1.Items[0]).Str = "ddd";
<br />
for(int i = 0; i < comboBox1.Items.Count; i++)<br />
{<br />
comboBox1.Items[i] = comboBox1.Items[i];<br />
}<br />
<br />
and i also trie to put the code of changing the item in the click event - NOTHING - NADDA - the combo box doesn't reflect the change.
If you succeed in this simple task it would be nice if you POST this code.
Thanks again - Ilan
|
|
|
|
|
Ok, problem sorted
There is a method in the reflector class called RefreshItem(int index) which when called redraws the item, looking in reflector at the code all it does is this:
comboBox1.Items[0] = comboBox1.Items[0];
Which forces the combobox to reload the data. What is happening is that becase you are changing a property of the item not the actual item itself the combobox has no way of knowing when an item has been changed because the item class does not raise an event stating that it has had a property changed.
Now for the problem, ComboBox.RefreshItem(int index); is protected overrides so you cannot call it, but by looking in reflector you can see what you're supposed to do and do it yourself.
So in summary after you have changed the property (Str), do this:
comboBox1.Items[index] = comboBox1.Items[index];
It works
Thanks for pointing out this "bug" to me though
Ed
|
|
|
|
|
Well Ed - Now we agree on the problem and its solution
However - when you say "reflector" what do you mean, i don't know this tool.
Ed.Poore wrote: ow for the problem, ComboBox.RefreshItem(int index); is protected overrides so you cannot call it, but by looking in reflector you can see what you're supposed to do and do it yourself
Thank again for sharing my problem.
Ilan
|
|
|
|
|
Well i think i found it "Reflector for .NET" from Lutz Roeder... Or maybe you are using other tool?
|
|
|
|
|
No that's the tool, you havn't come across it before?
It's a godsend
Ed
|
|
|
|
|
I am seeking information about developing a "Virtual Network Adapter" for Windows Machines.
Any technical development info.
Any possible open source developments.
Etc.
Think Hamichi, but customized for my usage.
Thanks in Advance,
ATM
|
|
|
|
|
Not C# but this is open source.
You want the bits relating to TAP Win32 Virtual Network adapter thingy-ma-bob.
Ed
|
|
|
|
|
wow, thank you... I was needing that direction.
Let me see what i can make of TAP Win32.
Thanks Again
|
|
|
|
|
Hope it's not overly complicated for what you need.
Have fun
Ed
|
|
|
|
|
Hi, I`m working with visual studio 2005 C#.
When I run my code the picture is displayed in pixels, but I need to display it in millimeters?
string path;
Bitmap image1;
path = OpenFile();
if (path != null)
{
image1 = new Bitmap(@path, true);
...
Valiovalio
|
|
|
|
|
Hi.
I recently made an account at brinkster.com (free educational package) and was assigned some free space to store files etc. My site address became www40.brinkster.com/mySite, where mySite is my username and folder i have manually uploaded files into. Now i want to upload file in this same directory using a simple winform c# application. I wrote this simple code:
WebProxy myProxy = new WebProxy("http://address:port/",true); //i m using a proxy server
WebClient Client = new WebClient();
Client.Proxy = myProxy;
Client.UploadFile("http://www40.brinkster.com/mySite/recieve.aspx","POST","c:\\text.txt");
I have this script recieve.aspx to recieve files and store them in the same directory as its i.e mySite
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>
void Page_Load(object sender, EventArgs e) {
foreach(string f in Request.Files.AllKeys) {
HttpPostedFile file = Request.Files[f];
file.SaveAs("\\path\\mySite\\" + file.FileName);
}
}
But i get an error:
"The remote server returned an error: (500) Internal Server Error."
Incase of GET instead of POST:
"Cannot send a content-body with this verb-type."
** Dont know abt if the directory has permissions or my proxy needs credentials(if its the case) or do i need to login first using this c# application the same way i do to get to mySite folder manually with browser using my brinkster login and password**
I am stuck with it for quite sometime now..kindly help me out with this. Thanks.
|
|
|
|
|
Firstly you'd best eliminate permission problems, create a simple aspx page for testing purposes where you write a text file to the current directory, just specify a filename with no path when saving the text file as this will save into the current directory.
(Or even better if you know a way (sorry I don't use ASP.NET that much) of getting the directory containing the aspx file then prepend this to the filename).
If you can create the text file (test by navigating to it in your browser) then you have sufficient permissions. If not then it's another problem.
Ed
|
|
|
|
|
ok so its resolved. yay. i dint have the write permissions on the folder i was uploading to.
|
|
|
|
|
hello
i want to hide my IP, when I connect from client windows app to a web service.
i can go through a proxy very easily like
MyMath.Math math = new MyMath.Math();
IWebProxy proxyObject = new WebProxy("http://proxyserver", true);
math.Proxy = proxyObject;
but how can i make a chain of proxies?
thanks
|
|
|
|
|
IIRC, you can only specify the first "hop" proxy. Your other downstream proxies would have to be configured to forward the request on their own.
But why would you even want to do this anyway?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there such a conversion? I would like to use DateTime as part of a unique identifier. I could create a number by appending year + month + day + hour + minute + second + ticks, but i am hoping i could access the number representation of DateTime like i could in VB6.
|
|
|
|
|
Use the Ticks property.
---
b { font-weight: normal; }
|
|
|
|
|
The ToBinary() method will return the DateTime 's numeric value.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Both advice is good.
Thanks for the "kick" in the right direction!
|
|
|
|