|
While it may be annoying, it certainly isn't strange. When crossing application boundaries (including distinct AppDomains), .NET Remoting marshals the call to another context, similar in concept (regarding this discussion) to your code calling another class's code. Depending on derivation and location, the method must be public in order to call it.
If you absolutely don't want to make it public, there is a way although it is difficult. You can extend RealProxy and the ProxyAttribute (with which you attribute your class that defines the handler). The RealProxy derivative can catch method calls (as well as other types), which you can use to override the default behavior so that the delegate is serialized. It's tricky, and if you're not too familiar with .NET Remoting I suggest you pick up a book like "Microsoft .NET Remoting" from MS Press[^] or "Advanced .NET Remoting" from Ingo Rammer[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I am trying to print out a datagrid, and I have code that works fine, but it won't print the data in sorted order if it has been sorted in the datagrid. It still prints the original order. How can I access the rows in sorted order instead of in the original order? theTable.Rows[i] is what I've been using to loop through the rows, but is there anything else I can use so that I can print the grid sorted.
Thanks,
Blake
|
|
|
|
|
DataTable.Rows will always present the original order, but you can use a DataView to sort and get the sorted order of the contained DataRow s. You can do this like so:
DataView view = new DataView(myDataTable);
view.Sort = "myIDColumn";
foreach (DataRowView rowView in view)
Console.WriteLine(rowView.Row.ItemArray); You should be able to get this using theTable.DefaultView , which should return the DataView in its current state that the DataGrid used to sort or filter the data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi all. Does anyone know if the .Net databound web controls use DataBinder.Eval(objDataItem, sPropName) for determining field values from data sources? For example, does a DropDownList control use DataBinder.Eval to evaluate its DataTextField and DataValueField properties at run-time?
|
|
|
|
|
DataBinder.Eval uses reflection to data-bind your expression against an object. So, when you commonly see DataBinder.Eval(Container.DataItem, "SomeProperty") reflection is used to find the "SomeProperty" property of the container's current data item (while declared as an Object , it's Type is whatever type is data-bound, like a list or a DataTable . The ListControl.DataTextField and ListControl.DataValueField are used by the overridden OnDataBinding event handler while enumerating the DataSource (with regard to the DataMember ) to get the current data item's property. If you use ildasm.exe, you can see that DataBinder.GetPropertyValue is actually used in this case.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi,
Can anyone tell me how a web service would get the calling computers IPAddress? I'm new to web services and I'm not sure where to look for this type of information. It's probably something really obvious that I'm unaware of.
Thanks
|
|
|
|
|
Domain Name Services, or DNS. This is all handled by the TCP/IP stack on your machine. This is what resolves names like www.codeproject.com to IP addresses like 209.171.52.99.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
I looked at the Dns class, but I didn't see anything obvious that would help me find out the calling computers ip address of my web service. Is their a way to do this?
Thanks
|
|
|
|
|
You can use Dns.GetHostByName (or the asynchronous BeginGetHostByName ) to get the IP address, but you don't need to in most cases. When the proxy makes a request to the remote Web Services via its URL, the DNS client of your local machine will resolve the IP address, connect to the server, and make the request on the Web Service. This is all done internally - you do not need to resolve the IP address manually, just like you don't need to use the IP address in Internet Explorer and other Internet-ready applications.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
So all I need to do is add this code to my web service and this will get the calling programs ip address?
string sHostName = Dns.GetHostName();<br />
IPHostEntry ipEntry = Dns.GetHostByName( sHostName );<br />
string sCallingAppName = ipEntry.HostName;
Thanks
|
|
|
|
|
If you want to log the IP address of the machine making the request to your web service, all you need to do us is get Context.Request.UserHostAddress inside a method call in your web service (Context is a property inheritted from the WebService from which your web service derives).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks so much for your help, this is exactly what I needed.
|
|
|
|
|
We have a beta .NET/C# application that we release every couple for client computers to install. They install it over their previous version.
We are finding that there are multiple entries in the Add/Remove Programs section even though there is only one installation on their machine - I assume that there is one entry per upgrade.
Any way to avoid this without manually removing the excess entries from the Add/Remove Programs?
|
|
|
|
|
Make sure in your installer project you set RemovePreviousVersion is set to True and always keep the UpgradeCode the same. To fix any current problems, you can use Orca (from the Windows Installer SDK) to add the necessary entries to the Upgrade table in your installer package (.msi file). See the Windows Installer SDK on MSDN[^] for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi!
I read some articles about P/Invoke and how to call Win32 API functions.
Now I wonder: when does the runtime load the DLLs and when does it free it?
Does it load the DLL when the external function is needed and frees it immediately after calling (so many calls to the external function would be slow and the DLL couldn't "remember" anything), or does it load the DLL one time and there is no manual way to control this (i.e. we can assume the DLL is loaded and we have no way to release the DLL ourself, the DLL could remember things like global variables in it set by the .NET program).
Thanks in advance,
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
The runtime loads the DLLs when the P/Invoke method is called. The proc address is found only once, which implies that the DLL remains loaded. I do a lot of interop (one could say it's my forte') and maintaining state has never been a problem.
Note that if you want to load and unload native DLLs you can always P/Invoke LoadLibrary(Ex) , GetProcAddress , and FreeLibrary .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
when i do this:
string unicodeString = "This string contains the unicode character";
// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
and I try to convert a Hebrew string to ascii I got in the asciiBytes
the number 69 (equals to '?')
but in english it's work just fine.
What is the problem?
Thank you in advanced,
Eran.
|
|
|
|
|
You have to use the Hebrew codepage. See Encoding.GetEncoding .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
What I want to do is have a background image on my tabpage that does not move when the tabpage's scrollbar is moved.
Right now what I am doing is in the tabpage's paint method I am drawing the bitmap:
pe.Graphics.DrawImage(bmpTabBack,0,0);
I have overriden WndProc and when I get a WM_VSCROLL message I do:
Invalidate(false);<br />
Update();
This does keep the background image in one place but there is some flickering if you move the scrollbar up/down really fast.
Is there another method that I can use to make it so that the background image never moves and there is no flickering?
Thanx for the help,
-Flack
|
|
|
|
|
You could try enabling double-buffering so that the image is drawn to a compatible off-screen bitmap and then swapped to the screen's device context. To do this, see the ControlStyles enumeration, specifically the DoubleBuffer member. Use Control.SetStyle in your contructor to enable the three necessary styles along with true as the second parameter. This should help.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey All,
I am looking for some advice. I am pretty new to C# with a little experience making form based windows applications that are pretty quick and dirty just to get them done (such as my psudeo translator that allows me to replace characters in a resource file with Japanese characters to test localization of products.) However I am trying to do something new which is to create an application that has multiple forms, however I am not a big fan of having several different windows open on the screen free floating when they could be wrapped in a single window. I would like a cleaner solution than closing one window with form1 and opening a new window with form2 on it.
After looking at my options I came up with several ways of doing this:
1) Instead of creating several forms, just use several panels that hide the controls based on a view switch. This seems cumbersome to do with the form designer, but seems possible if I hand write everything. I think this would work the way I want it to. Also I am a little afraid that this might mean all the code is in the form1 class which would be hard to maintain.
2) Not sure if I could just create a custom control that mimics the functionality that I looking for and then hide and show these based on views. This would allow me to create different elements of each control and re-use some other external controls such as listviews for displaying drag and drop elements. Not sure what I just said or if I can accurately express what I was thinking.
3) Rewrite the MFC Formview architecture in C#. Sounds like a lot of work but it may be worth it in the long run. Then I can feel like I accomplished something. Just not sure that it would be any better than a simplier idea though....
Any advice from someone that knows a bit more... Am I missing something (other than my own sanity)?
Thanks,
Brian
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|
|
If you just don't want for your other forms to show in task bar, then set ShowInTaskbar property to false.
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Thanks for the suggestion.
My biggest problem with multiple windows is the flow and controlling the user experience. I know that I often get frustrated with the amount of free floating windows in some applications and trying to get them positioned just right so I feel like I can use them. I don't mind dockable windows but only within the context of the view. I also don't really like a completely dialog based application with a stagnant main window. Sometimes I wish I was just plain satisfied but no I have to have this critical streak in me....
If I show and hide each window but it is not in the task bar then how do they get back to the correct window? I guess I could mimic switching by having the previous form size the next form to its own size, then tell the previous form to hide itself (both minimized and remove itself the taskbar). It seems lit a bit of a hack but I think it might work. Not sure what the performance would be like.. Is there a way of sharing menus and toolbars between forms?
Any other ideas or opinions?
Thanks,
Brian
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|