|
Hi,
I have two exactly identical classes. i would like to cast an object of one class to another. Normal casting did not work . Do somebody have some thoughts ?
James
|
|
|
|
|
(1) Have them share a common Interface than use the Interface.
(2) Create a copy constructor on one or both of the objects.
|
|
|
|
|
Hi All,
I have a Tab control having a tab Page on it. I have a panel placed on the tabPage, the AllowDrop property is set to true for all three of it. I still don't know why my panels DragDrop is not firing. Even when I try to DragDrop a Usercontrol on TabPage the cursor shows a circle and a line in between i.e meaning I can't drag drop anything on it.
Please let me know the solution. The Drag Enter of panel is firing.
Thomas Chacko
|
|
|
|
|
hi thomas,
can u let me know how u resolved this issue.
I am having a similar problem.I have tried the
Loaded += delegate
{
IntPtr windowHandle = new WindowInteropHelper(this).Handle;
typeof (DragDrop).GetMethod("RegisterDropTarget", BindingFlags.Static | BindingFlags.NonPublic).
Invoke(null, new object[] {windowHandle});
};
but still the drop is not happening,Only drag works.
Please help.Have spent nearly a weak on this.Thanks
|
|
|
|
|
hi all,
how do i know if the currentrow changed or not?
is there a boolean like mydatagrid.currentrow.changed that i dont know to check this state ?
help please.
|
|
|
|
|
I found some information about the RowState property. This property tells you if that particular row has been modified. Hope this gets you in the right direction!
|
|
|
|
|
Hi!
The situation is a bit more complex than i could formulate it in the subject.
Basically the problem is the different user rights situation running a process as a child-process of aspnet_wp.exe than starting it directly as the logged on user.
I'll try to explain the situation, and if you have any idea where else to search, please post it.
Maybe you might use this approach for you own needs, so i'll decribe it a bit more in detail.
Image the following situation (using .NET 2.0, VS80, c#, c++):
A c# console application is creating the COMServer ("Host.exe") with moniker binding:
object boundhost = System.Runtime.InteropServices.Marshal.BindToMoniker ( monikername );
It is possible to get the correct COM interface like shown below and use it:
IAnyInterface usefulobject = boundhost as IAnyInterface.
Furthermore, the console application provides a .NET remoting object, that uses functions of that bound COMServer:
System.String filename = "Server.exe.config";
System.Runtime.Remoting.RemotingConfiguration.Configure ( filename, false );
System.Console.ReadLine();
[...].
public class ServerObject : System.MarshalByRefObject
{
[...]
public void CallCOMMethod()
{
if ( usefulobject != null )
{
usefulobject.CallTheMethod();
}
}
[...]
}
When starting the Server.exe (console application) it is running as a regular user process, and the bound Host.exe is running under ..\winlogon.exe\services.exe\svchost.exe\Host.exe (visible with ProcessExplorer; thank you guys for that great tool!).
Everything is fine, and i'm able to talk to my COM object via .NET Remoting.
The next part causes some trouble: I try to start and stop the console application remotely with use of a ASP.NET 2.0 WebService (e.x. LaunchService.asmx):
[System.Web.Services.WebMethod]
public bool LaunchServer ()
{
System.Diagnostics.Process p = new System.Diagnostics.Process ();
p.StartInfo.UseShellExecute = true;
p.StartInfo.FileName = "D:\\Anydir\\Server.exe";
p.StartInfo.WorkingDirectory = "D:\\AnyDir\\";
p.StartInfo.Arguments = "";
p.Start();
return true;
}
The LaunchServer WebMethod call starts the Server.exe as child process of aspnet_wp.exe as user ASPNET and the Server.exe as well.
Regardless of the console output which is missing, I route all outputs to System.Diagnostics.Debug. and i see that the server is running.
First, I had problems reading a file, so i moved the ASPNET user into the group of Administrators (do not try that at home!!), just to see whether it is technically possible at all to use remoting channels from service-processes.
Yep. excellent.
Calling the right method on the remoting object, the Host.exe starts up and the returned object is stored in the Server.exe and can be used.
This is only possible for COM object, providing no COMEvent interface !
Objects, which are providing COM event sources are not loaded:
[
coclass,
threading(both),
aggregatable(never),
support_error_info("IAnyInterface"),
vi_progid("COMObject.AnyObject"),
progid("COMObject.AnyObject.1"),
version(1.0),
uuid("{B2D69299-C894-4032-BA07-1AAC494D3D01}"),
helpstring("AnyObject Class"),
event_source(com)
]
class ATL_NO_VTABLE CAnyObject :
public MyComBaseClass,
public IAnyInterface,
public _IAnyInterfaceEvents
{
public:
CAnyObject();
virtual ~CAnyObject();
__event __interface _IAnyObjectChangedEvents;
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
void RaiseEvent()
{
__raise OnChanged( x );
}
[...]
}
The exception when the Server.exe is trying to get the COM object like above and link to its event source is:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.InteropServices.ComTypes.IConnectionPoint.Advise(Object pUnkSink, Int32& pdwCookie)
at COMObject._IAnyObjectChangedEvents_EventProvider.add_OnChanged(_IAnyObjectChangedEvents_OnChangedEventHandler )
at COMObject._IAnyObjectChangedEvents_Event.add_OnChanged(_IAnyObjectChangedEvents_OnChangedEventHandler )
at Server.BindToComObjectWithEvents() in ...
The event callback is registered in Server.exe like:
usefulobject.OnChanged += new COMObject._IAnyObjectChangedEvents_OnChangedEventHandler ( eventhanderinserver );
hmm..
Why is it possible to get a COM object and call its functions, but as soon as the COM object provides events and the event handler is about to link the callback, it raised the exception ?
I tried to configure with dcomcnfg.exe the privileges for the COMServer but nothing solved it (it's only working with the "Interactive User" setting on the identity tab).
The Server.exe is running as {machinemname}\ASPNET user and the Host.exe is running under my own account (belonging to BUILTIN\Administrators).
Any ideas ?
Thank you very much.
|
|
|
|
|
hi all,
how can i copy content of my datagridview to MS word and to MS Excel ?
i placed two button and 2 savefiledialog. and create files with the extentions xls or doc.
but dont know how to write in them ?
with using :
using Microsoft.Office.Tools.Excel;
using Microsoft.Office.Tools.Word;
these namespaces how will i going to achieve my aim?
would you please help me just for inserting a single row ( or even cell) of datagridview to ms word and ms excel ?
many thanks in advance,
bye.
|
|
|
|
|
try this code to transferring Datagrid control to excelfile
Response.ContentType = "application/vnd.ms-excel";
//create a string writer
string xlFileName = "Report - " + System.DateTime.Now.Ticks.ToString() +".xls";
string xlFilePath = Server.MapPath("../Reports/") + xlFileName;
System.IO.FileStream FS = new FileStream(xlFilePath,FileMode.Create);
StreamWriter Sw = new StreamWriter(FS);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
//create an htmltextwriter which uses the stringwriter
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
DataGRid1.RenderControl(oHtmlTextWriter);
Sw.Write(oStringWriter.ToString());
Sw.Close();
FS.Close();
Response.AddHeader("content-disposition","attachment;filename="+xlFileName);
Response.WriteFile(xlFilePath);
Response.Flush();
Response.End();
|
|
|
|
|
Message Closed
modified 27-Apr-15 11:11am.
|
|
|
|
|
|
have you any idea about generation of a signature. i am working on it from last many days, but i am unalbe to solve my problem, i read topics about it, every one says signature has this quality, it is secure etc, but no one says do it in this way. so i wrote this query, may some one reply me which can be useful. may any one tell me the algorithm or something useful.
muhammad mahmood ilyas
|
|
|
|
|
|
Hi guys
Can you guys please help me out with a C# program I'm writing? I would like to copy the content of a selection of cells (e.g. Range("A1","M150") from one workbook to another workbook at a specified location (e.g. range("B2",Missing.Value) This process will be repeated x number of times in a loop so I need this to be reasonably fast. My current method is extremely slow..
Thanks guys
Regards
Sydney_Sider
|
|
|
|
|
I have a program with a DataGridView on a Form, and another object that contains a DataTable. The object creates a new Thread and periodically changes the data in the DataTable. The DataGridView is bound to the DataTable, but only updates when the Form is forced to redraw. It seems as if the changes to the DataTable do not fire an event off to the DataGridView.
I use the following command to bind my DataTable to my DataGridView:
gridView.DataSource=dataTable;
and I change the data in my DataTable using:
dataTable.Rows[x][y]=value;<br />
dataTable.Rows[x].AcceptChanges();
Is there an alternate way of changing the data that guarantees an event is fired?
Or is there an alternate way of binding the DataTable to the DataGridView?
Is the problem that there are 2 threads, and they are not allowed to communicate?
Any help/advice is much appreciated.
Iain
|
|
|
|
|
Are you using a Dataset or not.
If not try using,
DataGrid1.DataSource = ds.Tables[0];
DataGrid1.DataBind();
ofcourse you will need to use a data adapter as well. If you fill the data adapter using the dataset its very easy to update. Try it.
If only they could see what I see in my mind
|
|
|
|
|
I'm using Visual C# 2005 Express and the .NET 2 Framework. Consequently I'm using a DataGridView rather than a DataGrid, and I only have need for 1 table, so I've gone for a DataTable rather than a DataSet containing a DataTable. Reading the Microsoft documentation I should be able to bind a DataGridView to either a DataTable or a DataSet (in fact it seems to be easier to bind to a DataTable as the DataGridView.DataMember property does not need to be set).
Thanks for your input, but if you can answer any of the 3 specific questions I asked, I'd be very grateful.
Thanks, Iain
|
|
|
|
|
Not sure if this is what you are looking for, but...
There is a tiny white [>] looking thing on the datagrid view in the upper right corner of the form object (design mode), and you can set the databinding from there. You can also select the form object and look at the properties list for the databinding section and do the same thing from there.
|
|
|
|
|
I've finally discovered the problem. It's a 'feature' of VC# 2005 which seems to mess up events in debug mode. If I run my code outside of VC# 2005 then the binding works fine, and the DataGridView is updated whenever I change the DataTable.
If anyone knows why VC# works like this, or how I can reconfigure VC# to avoid this problem, let me know.
Cheers, Iain
|
|
|
|
|
I am new to Dot Net.I have a VC++(MFC) application.
I want to add better user interface to my application using c# or may be VB.Net.
Which are the different ways i can do it??...can C++ code call C# code ?? should i implement as C# dll ??...or are there any other ways i can do it?
looking forward for reply
thankx in advance
Shailesh
|
|
|
|
|
Shailesh Halankar wrote: ...can C++ code call C# code ??
No, C++ cannot call C# directly. They cannot coexist in the same project.
Shailesh Halankar wrote: should i implement as C# dll ??
Yes. Two DLLs written in different .NET-compilant languages can coexist in the same solution and they can reference to each other.
Shailesh Halankar wrote: ...or are there any other ways i can do it?
Not any better ones I have known of.
- It's easier to make than to correct a mistake.
|
|
|
|
|
HELLO
Thanks for your reply..
I also want to discuss another thing or 2 with u
First is can i implement my C# developed UI component as a COM and call it from my VC.Net MFC aplication (as u said that VC.Net (mfc) application cannot call a C# DLL)....
Also If i want to give Net connectivity to my VC.Net MFC application i.e to be able to upload certain files over the network may be, then how can i do it in Dot net.Can i use Asp.net or ne other way??
thankx
regards
Shailesh
|
|
|
|
|
It is easier said than done. Firstly, take a look at this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkcominteroppart2cservertutorial.asp[^].
It will tell you that in order for C++ to call C#, the C# assembly should be written in such a way that C++ can treat it as a COM object.
In your case, you want the UI part to be in C#, and for business logic and processing part you want to continue the C++ MFC code. So the better way is to do the opposite - make the C# call your existing C++ code. Create a new C# project, create your UI, and when it is time to code the business logic, make calls to a C++ DLL. Convert your C++ code to a COM object. Then you can call it directly from your C# application. See here on how to do that:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkCOMInteropPart1CClientTutorial.asp?frame=true[^]
Now if you are too lazy to do COM, and if your C++ MFC code is not really so gigantic, you can consider a re-write. Create a C# project, create your desired flashy cool UI, and type in the business logic part in C# as well. As you have said "I am new to Dot Net" - by doing so you will be 1 step farther from calling yourself "new"...
Koushik Biswas
who else?
|
|
|
|
|
Hello
Thanks for your feedback
I still wana clear certain things
As u know my application is VC++ Doc-View application and, i want to create custom User controls like tree control in C# as a component DLL (may be) and want to add to my DOc View application frame.
Is this possible? if not...which other way can i solve the problem
My Problem is that i cannot rewrite the code as C# (as the VC APP is gigantic)
thnks in Advance
|
|
|
|
|
Sorry you cannot. Reason is simple - a user control in the MFC document-view architechture interacts with the framework using a unique messaging system. It is just not an external assembly that you plug in. The design is from Microsoft days when .NET was not there. A C# assembly can give you a GUI, but you cannot display it from a VC++ MFC document-view project. At least I am not aware of any miracle that will let you do that.
Now coming to what practical alternatives you have. Firstly, believe me the C# tree control is not that great a control. It has numerous limitations that will frustrate you immensely. The very concept of a cool control that lets you do plenty of bells and whistles might have resulted in your brain being "c-sharpized".
With some searching and luck, you will find numerous complex user controls/ Activex objects developed in C++ that you can highly use in your project seamlessly. If it is not a binding to use C# (which you can't), you may look around for cool controls developed in VC++. Codeproject has many, and other forums have many too.
If you are more specific about the exact kind of control that you want, I can do some parallel searching too, if you don't mind that is
Koushik Biswas
who else?
|
|
|
|