|
Use a hash table. Use the Add method to add the values, with the string as key, and the byte as value. Use the ContainsKey method first to check if it already exists in the table, so you don't add duplicates. To retrieve the values, use the Item method.
---
b { font-weight: normal; }
|
|
|
|
|
Ok.. so far so good!
Here's what I have:
Hashtable table = new Hashtable(); //-- Simple enough!
Here's the data:
table.Add("0x5628","0x5628, 0, 0");
table.Add("0x0818","0x0818, 1, 0");
table.Add("0x56ED","0x56ED, 4, 0");
Now, I want to enumerate through each element, and "Do stuff" with it... I thought this might work:
foreach ( object item in table)
{
MessageBox.Show((string)item.ToString());
//-- Do other stuff
}
...alas, though... it only displays a message as to what the object is, not what it contains. Ideally, I want to return a string from each element:
"0x5628, 0, 0"
From here I can parse it to my heart's desire... I just can't seem to get to the data portion. Any ideas?
|
|
|
|
|
You are calling the ToString() method on the object before you typecast it. That will use the Object.ToString() method that just returns the name of the class.
You have to typecast the object before you call any methods on it:
((string)item).ToString()
The call to ToString is of course completely superflous on a string object. Just remove it:
(string)item
---
b { font-weight: normal; }
|
|
|
|
|
Hi.
Have a remote object. This class has a method that generates and returns an image. I want to set this image to a picture box, on the client.
E.g:
picBox.Image = remObj.GetImage();
But when I run this code I get the following error:
“cannot find field nativeImage”
This error comes from 'System.Drawing.Image'
How can I stop this error?
How can I set the picture box image to an image created by the remote object?
Please note that I do not need help creating an image, just setting it to the picture box image from the remote object.
I am using C#, but I will be grateful for any assistance
Thank you for any help...
|
|
|
|
|
Note that there is a known bug in .NET remoting when trying to transfer large amounts of data over in a single call. The bug has been reported to exist when transferring 2MB or more of data in a single call, but I've found it to occur with less data than that.
Instead of transferring the entire image over in a single call, transfer a stream of bytes over in a single call, then call stream.Read(...) to read bytes incrementally in multiple calls. Once all the bytes are transferred over, you can reconstruct the image on the client and set the picture box's image accordingly.
See this article[^] for more information.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
Hi everyone,
I need help using WebRequest and WebResponse.
Scenario: I want to send some data to a server and recieve it's response.
Code:
<br />
<br />
WebRequest myWebRequest = WebRequest.Create(sURL);<br />
<br />
myWebRequest.Method = "POST";<br />
myWebRequest.ContentType = "text/xml";<br />
<br />
string postdata = xmlcontent;<br />
<br />
ASCIIEncoding encoding = new ASCIIEncoding();<br />
<br />
byte[] postdatabytes = encoding.GetBytes(postdata);<br />
<br />
Stream requeststream = myWebRequest.GetRequestStream();<br />
<br />
requeststream.Write(postdatabytes, 0, postdatabytes.Length);<br />
<br />
myWebRequest.Timeout=10000;<br />
<br />
WebResponse myWebResponse= myWebRequest.GetResponse();
The GetResponse method just won't connect to the server, we have a connection log to see incoming requests.
Funny thing is that when I create a simply request without a request stream, it WILL connect to the server, through gets an error due to empty xml in the request.
Maybe there's a problem with the Stream?
-- modified at 9:45 Thursday 15th September, 2005
|
|
|
|
|
You can't just put xml in the data you post. That is not valid data in a request. If the request is invalid, it probably won't even register as a request in the log.
Put the data in the proper format for a request:
string postdata = "AnyKeyName=" + Server.UrlEncode(xmlcontent);
---
b { font-weight: normal; }
|
|
|
|
|
dont forget:
<br />
WebResponse myWebResponse= myWebRequest.GetResponse(); <br />
myWebResponse.Close();<br />
i had the same problem some time before
cu
|
|
|
|
|
hi, maybe u can help me, i'll apreciate!
first, sorry about my english.
I have some problems with security policy, and i duno the best workaround for that..
- I just finish a "installer.exe" (a WinApp in C#), this installer perform some process, do something on regedit, create virtual directory, things like that.
- This installer.exe stay on share directory on intranet server, our customers will put this installer on their intranet servers. So anybody should be able to exec the \\myserver\installers\intaller.exe or some like that...
- When the guys on their own station wanna run that installer, in specifics points they get the "System.Security.SecurityException" error
I workaroud this problem in my machine setting the .Net security policy to full trust.
BUT, no one wants to set the security policy in his machine, cause is boring, or they dont know how do that, and a installer shoul be convenient...
some body know ohter way to workaround this problem???
tanks!!
blitzkrieg bop!!
|
|
|
|
|
Hi!
You can create an msi file with security settings from the "Microsoft .NET Framework 1.1 Configuration" control panel and then install this together with your installer.
But you should not just set internet zone to "Full Trust" (as this will open a huge security hole!), but rather strong-name your installer and then only trust this assembly.
There's also (at least) an article here on CP dealing with code access security[^]
Regards,
mav
|
|
|
|
|
how to assign and get the session variable in javascript
m mohamad rafi
|
|
|
|
|
hi to all,
my axBrowser form will not work as a MDIChild form. when i make it an MDIChild of the parent form i get nothing in browser, soon as i take it out and just run browser form it works.
even basic browser with no functionality except onload event to load google doesnt work.
any ideas pls?
kind regards,
g00fy
|
|
|
|
|
In windows explorer you can select multiple files using combinations of ctrl and shift clicking, then if you click and hold the mouse button on one of the already selected files you can drag all the selected files to wherever. I'm trying to reproduce this kind of behavor in the windows forms datagrid, but the problem is that when I click and hold the mouse button on an already selected row (clicking on the row header) all the other selected rows get cleared (i.e. unselected) and only the clicked on row remains selected! I thought I could get around this by keeping track of all the selected rows, intecepting the MouseDown event on an already selected row and then restoring all the other rows that are supposed to be selected using DataGrid.Select. However, this doesn't seem to work. It appears that the rows get cleared *after* the MouseDown event and, therefore, after my code to restore the selected rows.
This is very frustrating!
Does anybody have any ideas on how I can make this work? I have to restore the selected rows while the user still has the mouse button down so that they can drag them or else stop the control from clearing the rows.
Thanks
[EDIT: here's a code snippet of what I've tried]
<br />
private void dgResults_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
<br />
bool shift = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;<br />
bool ctrl = (Control.ModifierKeys & Keys.Control) == Keys.Control;<br />
<br />
DataGrid.HitTestInfo hti = dgResults.HitTest(e.X,e.Y);<br />
if (hti.Type == DataGrid.HitTestType.RowHeader)<br />
{<br />
if (dgResults.IsSelected(hti.Row))
{<br />
if (ctrl)<br />
{<br />
}<br />
else if (shift)<br />
{<br />
}<br />
else<br />
{<br />
foreach (int i in SelectedRows)<br />
{<br />
dgResults.Select(i);<br />
}<br />
}<br />
} <br />
else <br />
{<br />
}<br />
}<br />
}<br />
|
|
|
|
|
You will have to subclass the DataGrid
Implement the following methods
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
...
}
public override bool PreProcessMessage(ref Message msg)
{
Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode;
switch (keyCode)
{
case Keys.Shift:
...
case Keys.ShiftKey:
...
case Keys.Alt:
...
case Keys.Control:
...
}
}
|
|
|
|
|
Thanks, by subclassing the DataGrid (which I was thinking I might do anyway so I could reuse the functionality) and overriding OnMouseDown method I can get the MouseDown behavor I want by simply not letting it call the base.OnMouseDown method when the MouseDown event occurs on an already selected row.
Now I have one more slight complication. If the use clicks down on an already selected row they might be getting ready to drag the selected rows, or they might just want to select that row only. The difference is whether they mouse up again. So on the MouseUp event I need to clear all the selected rows and reselect only the row the mouse is currently on. Trouble is that there is no DataGrid.Deselect function
Any ideas?
|
|
|
|
|
I had this problem and wound up actually keeping a separate list in memory that held whether a particular row was selected or not. It was a pain in the butt, but was the only way I could get the functionality to work. Too bad Microsoft didnt expose more of the DataGrid functions. All of the functions you need to override are there, but are either "internal" or "private", so there's not much you can do unless you hack your way into the framework.
|
|
|
|
|
Actually, I am also keeping an internal list of the selected rows as well just to save having to iterate through the whole table just to figure out which rows are selected. I agree it's a pain and a mystery why MS didn't add a DataGrid.SelectedRows property in the first place. One wonders if MS doesn't only provide the very basic functionality in the controls provided with the framework in order to create a market for developers to make and sell their own custom controls.
|
|
|
|
|
Okay, answered my own question. I can make it work by having OnMouseUp call OnMouseDown and setting a flag in the OnMouseUp method to tell OnMouseDown to let this "fake" mouse down event call the base method. It does seem like a awfully round-about way to do things though so does anybody have a better idea?
|
|
|
|
|
How embarrassing! I just found DataGrid.UnSelect!
Come on Microsoft, UnSelect? What was wrong with Deselect ?
|
|
|
|
|
Check your sorting with it. I dont have the code available to me, but I remember I ran into some problem that caused me to use my own list instead of relying on the DataGrid's because there was some deficiency.
|
|
|
|
|
I have a main dialog. I then create many new dialog forms which the user interacts with to enter values. I want to be able to retrieve the values that the user enters.
I am wondering the best way to design my system to allow access to the values entered by the user in the dialog forms. In my main form, I could add a public access to the dialog form instance. This seems inefficiant and seems to need a lot of effort to maintian.
Or perhaps I could update some central class with the entered values. Then I would access that class to retrieve the values.
I am sure this is a common thing that has to be done. Does anyone have suggestion as to the best way to achieve this?
Thanks,
Liam
|
|
|
|
|
There are loads of ways of doing this, here are 2
The simplest and worst of them is to change your controls to be public (I think this works, but would not recommend it)
Expose some public properties on your form to read the variables.
eg.
public string MyTextBoxValue
{
get
{
return TextBox1.Text;
}
}
you can also do clever things with a static factory method on the form which takes parameters as refs
HTH
Russ
|
|
|
|
|
I am trying to places buttons WITHIN a treeview control. SO, up in the top right hand corner you will see several buttons that perform several tasks. I have been able to anchor the buttons to the top right hand corner of the treeview control. However, when I introduce a splitter between TWO treeview controls, the buttons no longer anchor to the top right of the control. This is depedent upon the location of the splitter. For example, if the splitter is placed at the top of the control, then when the splitter is moved up and down, the buttons do not follow. However, they will continue to follow left and right when the form is resized. Any help would be much appreciated. Thanks.
D
|
|
|
|
|
I would use a toolbar placed exactly above the tree view, and not over it. Or put the buttons inside a panel, placed above the tree view.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
The problem with that is, I have two treeveiws ontop of one another. They are separated only by a splitter.
|
|
|
|