|
You can get a DataView from a DataTable no matter how it was created. After all, whether the records are read from a DataAdapter , added manually, or imported from an XML document, a DataSet is still constituted.
As I said before, reading data will not automatically sort your columns unless the data was already sorted. Instead, you can bind your DataGrid against a DataView which you can get from your DataTable (within the DataSet ) using either the DataTable.DefaultView or creating a new DataView , passing the DataTable over which you want the view in the constructor. See the documentation for the DataView class for more information.
Also, so that the sorting knows that a column is a number - as I mentioned before - you should create your schema. The DataSet will not resolve the schema location unless you use XmlReadMode.ReadSchema . You should still use ReadXmlSchema however, since your schema location may be different than what's used in the URI (which doesn't have to resolve to a path - it can be anything, even something like "asdf"). This way, you can also embed your schema as an embedded resource and ship it easily with your code, whereas the XML document would be arbitrary.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How do i get to a method defined in a .lib file? There is no LIBImport attribute, but that's ok because it's a compile time import, but i'm still slightly confused. Seing how a lot of objects and methods for C and C++ are defined in them, instead of DLL's, how would i go about using them?
Now, i've found most of the methods I want in the UnsafeNativeMethods, and i'd like to call them. How do i go about that?
Cheers
Cata
|
|
|
|
|
That's because you don't use the lib's. Use the .DLL's. The lib's that you see are only used when compiling C++ code and must be included in the project.
In your C# code, use DLLImport on the DLL of the same name and don't worry about including any libraries:
<DllImport("KERNEL32.DLL", EntryPoint := "MoveFileW", _
SetLastError := True, CharSet := CharSet.Unicode, _
ExactSpelling := True, _
CallingConvention := CallingConvention.StdCall)> _
Public Shared Function MoveFile(src As String, dst As String) As Boolean
' Leave function empty - DLLImport attribute forwards calls to MoveFile to
' MoveFileW in KERNEL32.DLL.
End Function
RageInTheMachine9532
|
|
|
|
|
I'm being a total muppet here.
user32.lib, the twin to user32.dll.
It just never said use the DLL in the documentation.
I will now go and jump off a cliff.
Ciou.
Cata
|
|
|
|
|
For any decent C/C++ developer, it's pretty obvious why the .libs are documented and the .dlls aren't. .libs are used to link against (either statically or dynamically) when you link your executable (after compiling the source). The reason the .lib is documented instead of the .dll is because you don't link against a .dll, but against a .lib. When the code is executed, the .dll is loaded and mapped. The .lib basically contains the information that the executable you're linking requires in order to resolve the APIs you're using, in general terms.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ahhh... gotcha.
Makes sense now. The lib describes the objects / methods so that the .exe can map them properly from the DLL call. When marshaling in managed code, all object descriptions are hard coded, so you link directly to the DLL's. (Is that right? I always find re-describing something in your own words is helpful in the learning process)
Cata
|
|
|
|
|
Hello,
My requirement is to show parent child relationship in datagrid in treeview format. Means on clicking + sign new grid should be open with thread from first one to new grid showing all child records, + sign if they have further childs. Upto that gird where no further child. I already used relationship but there parent records are shown in top portion of new grid. but this is not what required. Thanks for ur help.
Inpreet Singh
|
|
|
|
|
|
Thank you sir for ur reply. I search for other option on these sites.
|
|
|
|
|
Hello,
I am working in C#. Wanna use Resource files for storing message box strings in it. Then call required string using their specific names. Can anybody tell me how to create these files i tried to do the same but didn't manage to. Thanks for ur help.
Inpreet Singh
|
|
|
|
|
If you're talking about ResX files (or even .txt files can be used), you should see Resources in Applications[^] in the .NET Framework.
In VS.NET, this is pretty easy. With each form or control, VS.NET creates a hidden .resx file with the same name (only .cs.resx instead of .cs). If you click the "Show Hidden Files" button when your project is selected, you can see and edit these. They will be compiled into .resources files automatically. You can easily reference these in your class using something like:
ResourceManager resources = new ResourceManager(this.GetType()); ...where this is an instance of your class. There's other overloads for the constructor as well. Note that the ResourceManager will be instantiated for each instance of each class that uses it.
A better way is often to have a single class that has an associated ResX file and use a singleton pattern. This is common in all the .NET FCL assemblies and I and others I've seen use this in larger applications as well.
If you're building your project using the SDK and the command line, you use the resgen.exe utility to compile a .txt or .resx file into a .resources file with the fully-qualified name of the Type to which you want to associate it (btw, it doesn't have to be associated with a Type), such as MyNamespace.MyClass.resources to be associated with a Type MyNamespace.MyClass. When you compile these, you include all the .resources files as embedded resources (using the /res switch on csc.exe).
Read that section on resources in applications, though, and you should get a better idea.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I want to use resource files to store message box strings. I already read that I can, by defining Name = value pair in text file. like ex > Close = "Really wann quit this application". But now the problem is where should I wirte this text file and then where should I compile Resgen myResource.txt , to create myResource.resource file. Now after doing all this how should I use these Name of string in my application to call resource file. Thanx for ur support.
Inpreet Singh
|
|
|
|
|
Read about the ResourceManager class in the .NET Framework. I already gave you a "walk-through" of how to use it. The class documentation for ResourceManager even includes an example.
BTW, it's better to use ResX files (just XML documents) because you can specify a Type so that you can serialize more than just string (you can serialize anything with an associated TypeConverter like Size , Point , enumerations, etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a Win32 service written in C# that I want to create a front-end for (display status, progress, etc.). It would be nice to have a web-interface, but that whole asp.net thingy is a mystery to me (only if I could read!!!).
How should I do it? Actually, How can I do? Remoting? Web-service? So, if Win32 Service = Server, ASP.NET = Client! How to do?
Thanks,
Johnny
|
|
|
|
|
First, learn about ASP.NET by reading the .NET Framework SDK and sites like http://www.asp.net[^]. Don't just jump into something without knowing anything about it.
Second, you can use various ways to control your service. If the user under which ASP.NET runs has the necessary privileges, you can use the ServiceController class to execute commands on your service (so long as you override ServiceBase.OnCustomCommand ). You could also host a Remoting object from your service and communicate with it from ASP.NET, but you should also read about .NET Remoting because it is a difficult subject. You can read more about it in the "Microsoft .NET Remoting" book from MS Press[^] or from Ingo Rammer's[^] .NET Remoting book. Remoting will give you far more control than executing commands on a service (see the documentation for ServiceBase.OnCustomCommand and you'll see why)..
Keep in mind, however, that privileges here are important. By default, ASP.NET runs as the ASPNET local user. By default, this user account is VERY limited (as it should be). You'll have to make sure it can manipulate the service either by running the service as ASPNET (or whatever user you use if you change the machinePolicy section of the machine.config file) or giving ASPNET impersonation privileges and impersonating the account that the service runs as. Depending on your environment, code access security might also hamper your ability since the web application will need the ServiceControllerPermission and SecurityPermission assigned to it with the appropriate arguments (see the ServiceController.ExecuteCommand method for details).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was looking for something similar, but another way around.
I need to have windows service written that communicates with asp.net application.
I need that service to set some (complex datastructure) variables in asp.net application object.
Is it possible?
|
|
|
|
|
No, not easily (and do I mean HARD, since it would require using Directory Service Objects (DSO) to get the application and a bunch of other code to get the ApplicationState ). The easiest thing to do is to handle the Application.Start event (already hooked-up for you in your Global.asax or Global.asax.cs file) and query to get data for the application, whether that comes from a database or what. If you need to change this at runtime, another way would be to use a file (say, for example, an XML file) and store that in a cache object with a CacheDependency so that when you change the file the cache is invalidated and the data would be read next time, something like:
protected void Application_Start(object sender, EventArgs e)
{
HttpContext current = HttpContext.Current;
if (current != null)
{
Cache cache = current.Cache;
XmlDocument doc = cache["MyStuff"];
if (doc == null)
{
doc = new XmlDocument();
string path = Server.MapPath("/data/mystuff.xml");
doc.Load(path);
cache.Add("MyStuff", doc, new CacheDependency(path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.High, null);
}
}
} There's many other ways you can accomplish something like this without using services or remoting too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the response Heath. What I am looking for is not controlling the service (thru ServiceController), but to have the UI (whatever that may be) commuinuate with my worker threads in the service. Ignoring the difficultes of Remoting, do I use it in an ASP.NET just as I would in any other application type?
|
|
|
|
|
As I mentioned, you can use the ServiceController to execute commands if your ServiceBase -derived services overrides the OnCustomCommand . You still need an instance of the ServiceController for your service (using the service's registered name, not the display name) in order to call ServiceController.ExecuteCommand . Your commands are limited to passing an int , so you'll need to establish an identification protocol, like 0 = Kill threads or something like that. If you use bitwise operations, you could even use this int to have threads sleep for a time, such that the mask 0x80000000 indicates that threads should sleep while the mask 0x0000ffff gets the amount of seconds (or milliseconds, or whatever) to sleep.
If you need more control beyond that, you'll need to use remoting. You can use ASP.NET as a remoting client, but I wouldn't recommend it unless you're using a singleton pattern for a server-activated type (which would be the most likely choice anyway).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I wonder how to get the information of a file of dbf in c#.
For example,record numbers,the header information of file ,record data ,etc.
|
|
|
|
|
i have application that open word document when the user open the applicatoin and try to open another document from the application, the application starts new instance by shell command and passes the file name as parameter.
the problem is i always get the message "can not find the file specified"
but when i deguged the application and copyed the command string and tryed to ru it from the prompet it worked well.
here is my code:::
/////////////////////////////////////////////////////////////////////////////////////
string action="";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
string path = Environment.CurrentDirectory;
int pos=ienum.Current.ToString().IndexOf("bin");//get the first parameter
action=path+"\\Almogahed.exe "+ienum.Current.ToString().Substring pos+12);
ienum.MoveNext();
action+=" "+ienum.Current.ToString().Substring(pos+12);//get second parameter
proc.StartInfo.FileName=action;
proc.Start(); // file can not found why!!!!!!!!!!!!!
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
thank u
i did it by using
/////////////////////////////////
proc.StartInfo.Arguments=param;
/////////////////////////////////
|
|
|
|
|
How to set the focus on the treeview nodes for placing the Text in Drag Drop functionality.
I used Drag_Enter event in which , the
treeview.SelectedNode = treeview.GetNodeAt(e.X, e.Y) but
the treeview.SelectedNode always returns Undefined Vaule.
Also, wherever the treeview control was placed , instead of e.X , i used
e.X - treeView.Left and e.Y - treeView.Top
Still, i am not able to get the solution.
Can anyone look into this.
Thanks and Regards,
Viru
|
|
|
|
|
Never set the TreeNode under the cursor while dragging to the SelectedNode . It is NOT the selected node. Instead, you'll have to override the painting and - while dragging (which you can set a flag for instance) - paint the node under the cursor using the highlight colors and any appropriate colors from SystemColors .
The TreeView in the .NET FCL is very limited, and you often have to go to a lot of work for something like this. I recommend you look into tree controls like those from http://www.devexpress.com[^] and http://www.infragistics.com[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello buddies,
I am developing a web control, whose class is derrived from System.Web.UI.Control class. as you know Control Class doesn't include "Style:CssStyleCollection" Property which exists in System.Web.UI.Webcontrols.Webcontrol class. In the latter class this property is magically filled with 'styl'e attribute available in the HTML-side control's tag and I would really be thankful if someone tell me how this happens so I implement it in my System.Web.UI.Control based webcontrol.
Also Webcontrol contains Width and Height properties and all derrived webcontrols can be resized on the design surface of VS using resize handles arround their rectangle, I have added custom Width and Height properties to my System.Web.UI.Control based webcontrol and it works in rendered HTML and also in direct property assignment in properties panel and code, BUT on the design surface of VS it can not be resized with the mouse.
I appreciate any help,
- Den to Fly
---
"Art happens when you least expect it."
|
|
|
|
|