|
Am a newbie to .net so please can anyone help me out how to print only datagridview in a form with print preview option using C#.Net.
|
|
|
|
|
pradeepc_mca wrote: Am a newbie to .net so please can anyone help me out how to print only datagridview in a form with print preview option using C#.Net
Ref
cheers,
Abhijit
CodeProject MVP
|
|
|
|
|
I'm currently testing several ways to have one application get hold of an object from another application. Both are written in C# and wether I use IPC channels or WCF Service Contracts I end up with the same problem. If I use a simple class whose properties and methods only return the built in types (such as int, string or ArrayList) it works fine, but if I add another property of a custom made type I get an error. IPC gives me a InvalidCastException and WCF puts the channel in a Faulted state and it breaks. Obviously I'm doing something wrong and I hope someone can give me a hand. The server looks like this:
public interface IBase {
int IntTest { get; }
String StringTest { get; }
IOther OtherTest { get; }
String Test(String txt);
IOther Test3();
}
public interface IOther {
String StringTest { get; }
String Test(String txt);
}
public class Base : MarshalByRefObject, IBase {
public int IntTest {
get { return 4; }
}
public string StringTest {
get { return "A string from Base"; }
}
public IOther OtherTest {
get { return new Other(); }
}
public string Test(string txt) {
return "Base called with: " + txt;
}
public IOther Test3() {
return new Other();
}
}
public class Other : MarshalByRefObject, IOther {
public string StringTest {
get { return "A string from Other"; }
}
public string Test(string txt) {
return "Other method called with: " + txt;
}
}
The server is registered like this:
public MainWindow() {
InitializeComponent();
IpcChannel ipcCh = new IpcChannel("IPChannelName");
ChannelServices.RegisterChannel(ipcCh, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Base), "CName", WellKnownObjectMode.Singleton);
}
The client looks something like this:
IpcChannel ipcCh = new IpcChannel("myClient");
ChannelServices.RegisterChannel(ipcCh, false);
obj = (IBase)Activator.GetObject(typeof(IBase), "ipc://IPChannelName/CName");
Console.WriteLine("Returns: " + obj.Test("a text"));
Console.WriteLine("Returns: " + obj.StringTest + " " + obj.StringTest.Length);
Console.WriteLine("Returns: " + obj.IntTest);
Console.WriteLine(obj.OtherTest.ToString());
The last line gives me the InvalidCastException or, in the cae of WCF, the Faulted pipe. Please help.
|
|
|
|
|
Hi,
this may seem silly but it looks as if you've put the interfaces in the *server* application. This is certainly possible, but would require the client to have a reference to the server. Normally one doesn't want to deploy the server on the client machine so one would put the interfaces in a common assembly to be deployed on both client and server.
That said, if you have duplicated the interface declarations so that the code exists in both client and server assemblies then that is your problem - and it should indeed result in InvalidTypeCastException .
|
|
|
|
|
Hi and thanks for replying,
I have indeed duplicated the interface declaration in the client app. I put the interface in a shared assembly instead and that removed the InvalidCastException. Unfortunately it now wants the object to derive from MarshalByRefObject. As far as I can tell my remote able object does that already, as well as implement the IBase and IOther interfaces respectively. I don't have to put the implementation classes in the shared assembly as well, do I?
Actually, I just tried that but I still get the same RemotingException.
|
|
|
|
|
Hi again,
You should be able to use remoting regardless of whether you derive from MarshalByRefObject , though objects not so derived would be marshalled by value. In other words, if you instantiate such a "remote" object it would be binary serialized at the server, sent to the client, and deserialized there. In other words the object would live on the client and not really be a remote object at all. (However this technique can be used to allow a server to basically ship an implementation to the client.)
And you don't need the implementation to be in a common assembly.
It would be nice to know what the exception message you're getting is. And better yet if you could post the absolute minimum of code required to reproduce the problem.
|
|
|
|
|
I switched to WCF but still can't get it to work. Here is what my code looks like now:
The interface looks like this:
[ServiceContract]
public interface IBase {
int IntTest {
[OperationContract]
get;
}
String StringTest {
[OperationContract]
get;
}
IOther OtherTest {
[OperationContract]
get;
}
}
[ServiceContract]
public interface IOther {
String StringTest {
[OperationContract]
get;
}
}
It is implemented in both projects. I tried using a shared assembly but get the same result. My server now looks like this:
public partial class MainWindow : Window {
private Base fb;
private ServiceHost host;
public MainWindow() {
InitializeComponent();
fb = new Base();
host = new ServiceHost(fb, new Uri[] { new Uri("net.pipe://localhost") });
host.AddServiceEndpoint(typeof(IBase), new NetNamedPipeBinding(), "PipeReverse");
host.Open();
}
private void Window_Closing(object sender, CancelEventArgs e) {
host.Close();
}
}
And here is my implementation of the interface:
[Serializable]
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class Base : MarshalByRefObject, IBase {
public int IntTest {
get { return 4; }
}
public string StringTest {
get { return "A string from Base"; }
}
public IOther OtherTest {
get { return new Other(); }
}
}
[Serializable]
[DataContract]
public class Other : MarshalByRefObject, IOther {
[DataMember]
public string StringTest {
get { return "A string from Other"; }
}
}
The client looks like this:
public partial class Form1 : Form {
IBase obj;
public Form1() {
InitializeComponent();
ChannelFactory<IBase> pipeFactory =
new ChannelFactory<IBase>(
new NetNamedPipeBinding(),
new EndpointAddress(
"net.pipe://localhost/PipeReverse"));
obj = pipeFactory.CreateChannel();
}
private void button2_Click(object sender, EventArgs e) {
Console.WriteLine("Returns: " + obj.StringTest + " " + obj.StringTest.Length);
Console.WriteLine("Returns: " + obj.IntTest);
Console.WriteLine(obj.OtherTest);
}
}
Everything works like a charm except this line:
Console.WriteLine(obj.OtherTest);
It give me a CommunicationException with the message "There was an error reading from the pipe: Unrecognized error 109". As far as I can tell that is a broken pipe due to a faulted state but I can't figure out why. Any ideas?
A thanks for helping out, I'm getting so frustrated with this...
|
|
|
|
|
Hi All,
There is an interesting Article "Nav Autoupdate with c#" under Library section
Link:
http://www.codeproject.com/KB/library/AutoupateNAV.aspx
Thanks
|
|
|
|
|
Hi,
I am required to implement the reload process for display updated data if database has been changed by other user in Windows Forms, dose anyone has similar exp for share?
I am planned to use the polling method but dose it contain alternative solution?
Thanks.
|
|
|
|
|
What is your database, SQL 2005 has some extended functionality to support the but it is not simple.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
the target database should be mssql 2k, so dose it support this function?
|
|
|
|
|
Hi,
there is an alternative solution to polling. The technique itself is based on the observer pattern. The model (database etc.) informs all before registered listeners about a change in the model. The listener itself can then react accordingly.
You have two options to implement this:
1) Some database-server can inform registered applications (through the connection) about changes in the database. Check if you DBMS can do this (look for event or sth. similar).
2) Implement a layer which communicates between different hosts. Then use this layer to send a message to all registered applications that you performed a database change. (You should avoid using this solution. Better use your polling mechanism)
Hope this helps.
Regards
Sebastian
|
|
|
|
|
1. The target database should be mssql 2k, so dose it contain an event for supporting this feature? or any keyword can help for search? I don't know what kind of term can be used for this "feature".
2. New layer for communication should not work if my target is 2 tier (client program and mssql database), so I don't know where should place the layer if without server application.
Thanks~
|
|
|
|
|
FYI, I've read on and noticed you need this to work with MSSQL Server 2000.
You've said little about your scenario so it's a bit tricky to give any advice. So this is just some general info instead.
The database does not provide anything that makes it directly easy to provide an event in your application. It is possible though. One way is to write an extended stored procedure in C++ that notifies your application (for example using a message queue) that the update has taken place, and then call this from a trigger in the database.
Another option is available if the database is (supposed to be) accessed only via your client app and you can update all installed clients before the feature becomes (fully) functional. In this case you could use remoting or message queues or web services or even sockets (if you like to needlessly complicate things and reinvent the wheel ) to notify all clients when any client has just modified the data in question.
To be honest, I think polling is a better option. Just remember that if you've got loads of clients and poll frequently it will generate considerable load on the database and it may be smart to put a caching server in the middle. 500 clients polling every 5 seconds is 100 requests per second. If you've got such a case, consider making an app that polls the db every 5 seconds and updates a cached value (such as a timestamp). Then clients can poll this app (which of course responds based on the cached information) without having to acquire shared locks in the database and the rest of the overhead of executing some query a hundred times per second.
|
|
|
|
|
Hello I want to draw a text along an array of Points
Any suggestion for a good approach ?
Thanks for any help
|
|
|
|
|
Do some research on the GraphicsPath class.
That should give you some ideas.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you
Yest it sounds interresting
I'm trying to figure out what are the "Byte [] types" in the constructor of a Graphics path
|
|
|
|
|
baranils wrote: I'm trying to figure out what are the "Byte [] types" in the constructor
I wouldn't worry too much about that for now. I don't believe it will help to solve your problem.
Look at GraphicsPath.AddString and GraphicsPath.Warp methods.
[Edit]
Also take a look at this[^] article from here on CP. It's in VB but I'm sure that will not be a problem. There are loads of code converter apps on the web, if you are unable to do it yourself.
[/Edit]
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
modified on Thursday, April 16, 2009 6:53 AM
|
|
|
|
|
I see !
So finaly GraphicsPath needs a TransformMatrix !
I was expecting that the graphicpath string will automaticaly follow the path defined by the array of point
So what makes the worth of the GraphicPath for this purpose ?
Maybe it will be more simple to use a Graphics.DrawString directely, cutting the string into small pieces
|
|
|
|
|
I've just edited my previous post. Take a look at that, and come back if you still have problems.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Just in case you are still having difficulties, I have found a source in C# here[^]. Jolly good it is too.
Hope this helps.
baranils wrote: I was expecting that the graphicpath string will automaticaly follow the path defined by the array of point
Come along now, this is MS we are talking about. Do you really expect that they would do anything to make our lives easier?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you very much
This is a piece of work !
|
|
|
|
|
It's a pleasure. Your question raised my interest, so I did a bit of rooting around, and got lucky.
Although your English is very good, I am guessing that it is not your first language (your location also gives a clue). So FYI you might want to be a little careful about using the phrase:
baranils wrote: This is a piece of work
In colloquial English it actually means the opposite of what I think you meant. At least what I hope you meant. As an example if you know a particularly nasty man, you might say "Now he's a piece of work isn't he?".
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Get it !
Better to say : it's not a piece of cake
|
|
|
|
|
Hello all!
I'm wondering if anyone has any idea to generate specific frequencies?
I am aware of Console.Beep(), but that plays through the PC-Speaker (Or Console Speaker, as it says in the tooltip)
I'm wondering if there's a way to do this to play through your regular sound device (Eg: Speakers / Headphones)
I thank you for your time!
- Reelix
-= Reelix =-
|
|
|
|