|
Hi,
I'm wondering if there can be any problem related to using a datadrig bounded to a dataset that is updated by temporary methods called from different timers:
<br />
OnTimer1 () { put data into data set table 1}<br />
<br />
OnTimer2 () { put data into dataset table 2 }<br />
<br />
Datagrid uses dataset to show data inserted by the two timers.<br />
After a few updates on the dataset, de application throws a System.NullReferenceException in system.windows.forms.dll (Object reference not set to an instance of an object).
Could it be that I'm using DataView's to search for records to update in the timers? Well this as proved to be a great headache to me, I appreciate your atention.
Best Regards,
Anfernius
|
|
|
|
|
Using a DataView is not a problem. With a lack of more detailed information, it's impossible to help you. You need to debug your code: step through your code and find where the NullReferenceException is being thrown.
Also, when a NullReferenceException is thrown, this often points to badly written code. There is no excuse for this exception - always check your variables to make sure they're not null before calling methods on them. If you're expecting data in a particular DataTable within your DataSet , for example, and no data was returned, that DataTable reference could be null (depending on whether or not the DataSet was filled with schema information). Calling a method on that DataTable without checking for a null reference would throw a NullReferenceException . Checking the return value, using a typed DataSet , and programmatically adding a new DataTable with the appropriate name would get rid of this problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This Exception may be thrown when you try to change data in the same time as DataGrid reads them. Try to suspend binding before changing data from timer thread, or try to use Invoke method of the datagrid and then call your changing methods.
I am less sure the 2nd method, but it may work.
h.
|
|
|
|
|
Hi,
I have a text box on my form . I want to move the text box to the position where the user clicks. So I kept the location in variables and I am getting the coordinates of mouse click. How do I repaint the form so that the text box appears at the mouse click position.
Karteek
|
|
|
|
|
So, what is your problem? Just set the new X and Y values of the textbox and call the Refresh () method of the form if required.
Don't forget, that's Persian Gulf not Arabian gulf!
Murphy: Click Here![^] I'm thirsty like sun, more landless than wind...
|
|
|
|
|
|
Setting TextBox.Location will move the textbox to the new position, no calls to refresh required; the form will refresh itself automatically.
#include "witty_sig.h"
|
|
|
|
|
hi all
can anybody tell me about functions in c# like _inp & _outp in VC++
or can u tell me how can I access 378,379,37A (parallel port) using API functions or C#
thanks for all
|
|
|
|
|
|
just search NTPort in google.
/\ |_ E X E GG
|
|
|
|
|
Hi,
I've noticed that when you load a second Form (set to TopMost=true), that the cursor does not activate (show up) in the textbox set to TabIndex=0. Click back to the first Form and then back to the second Form, the cursor shows blinking away. Any ideas on how to fix this?
thanks,
Ron
|
|
|
|
|
Are you using Show or ShowDialog ? In the former case, also try calling Activate on your form after calling Show .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath!
I'm using a Show (it's a Find/Replace Form for a notepad like application)...
I'll have to give that a try (I'm at work now).
One way I was able to correct this was to call the TopMost just after the Show call and not set in the Find/Replace Form.
One other question... when you have a TopMost Form and you want to click onto the original Form (back to editing the richtextbox but keeping the Find/Replace Form open) how do make it so ONE click activates the original Form and places the cursor where you clicked?
Ron
|
|
|
|
|
One click will activate the form. To set the cursor, override OnActivate , get the current mouse coordinates (in screen coordinates) using the static Control.MousePosition property, convert those coordinates to client coordinates by calling PointToClient on the Control and then set the insertion point in whatever way the control supports.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can't get this to work at all.
If i use vba i use:
myRange.copy
myRange.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
what i'm trying to do is paste the data back to where they originally came from. In c# though, there is no overload for copy that doesn't take arguments.
has anyone done copy and pastespecial before, or know another way of getting c# to convert a range from references / formulas to values. The code will be called up to 5000 times per run of the application, so while it doesn't need to be lightning fast, it needs to be quicker than looping throught the cells and setting their values individually.
Thanks
Russ
|
|
|
|
|
i've solved this one, the copy method is more than happy with a param: Type.Missing
Variants make c# a pain for this office lark.
|
|
|
|
|
I have been tasked with updating a VB.NET application which was written by a developer who is no longer with our company. I would prefer to slowly convert the VB app to C# over time, but simply do not have the bandwidth to do the whole thing right now.
I would like all the updates added to the application to be made in C#. Is it possible, since both languages are compiled to IL, to embed C# code within a VB application, and how might one go about doing such a thing?
|
|
|
|
|
It's not possible to embed C# within VB.NET source, sadly. You could, however, add any new functionality to a seperate dll. Your VB.NET code can easily call your C# code and vice-versa.
FYI, there's lots of programs out there, including some free ones, that automatically convert C# to VB and vice-versa. I suggest doing a google search if you're interested in that.
#include "witty_sig.h"
|
|
|
|
|
As Judah said, you could can easily communicate with both because they do compile to IL (this is the fundamental principal of the CLI). A single compiler can't handle both, though.
If you want to maintain a single DLL with this, however, there is a way (though VS.NET 2002 and 2003 won't be any help). You can compile either the VB.NET or C# source to a module using the command-line compiler and passing the switch /t:module . When you compile the other language source, you can embed this module into your assembly using /addmodule:filename on the command line, along with the rest of the params (like /t:dll ). Your assembly now contains two modules that define the IL. Consumers of your assembly won't know the difference (unless they used a disassembler, but that really doesn't matter).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How do I save the data in a list view to disk? I have read books and searched the internet. A code sample would be great because I am a begginer. Actually any help would be appreciated.
|
|
|
|
|
Writing to disk is as simple as opening a stream and feeding it bytes. There are special streams available that let you feed in text too. Here's some example code that writes the text of the items of a ListView to a text file on disk:
using System.IO;
...
StreamWriter writer = File.CreateText("c:\\test.txt");
foreach(ListViewItem item in listView1.Items)
{
writer.WriteLine(item.Text);
}
writer.Flush();
writer.Close();
#include "witty_sig.h"
|
|
|
|
|
What kind of help files does .NET support?? I am converting my application from java to C#.. In the older case i have a .hlp file for providing help..But i found C# doesnt support .hlp file..so i decided to convert this to .chm file.. So before i do this i want to know whether C# really doesnt support .hlp files or not??? I have tried MSDN and couldnt get any info saying it doesnt support .hlp..instead i found many articles on .chm..
Thanks in advance
Sudhakar
|
|
|
|
|
It supports CHM, but you can use whatever help you want if you provide the implementation by handling the HelpRequested event (or overriding OnHelpRequested in derivative controls).
IMO, CHMs are much better anyway. It's a better interface, easier to write for (you can use any HTML too and the HTML Help Workshop, where writing .hlp files is bit more of a pain).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Stewart..
I already had the code for the above events.. but i have the problem with the following..
--------
I have my old application in java(Microsoft VJ++) and this application uses winhelp file(.hlp) to provide help for the application. This application has a form and a help control on that..when i clicked it , it displays the help related to the form..Internally the code looks like this..
Help help = new Help();
help.showHelp(string helpfilename.hlp, string topic id);
Ex; helpfilename looks like "x.hlp"
Topic id as "906"
---
I have converted the above application to .NET framework..I am using C# as the language..
So i want to know the equivalent function for the above.. I tried using the following code as a replacement for the above.
HelpNavigator navigator = HelpNavigator.Topic;
System.Windows.Forms.Help.ShowHelp(this, "helpfilename.hlp", navigator, "topic id");
So i used this code:
HelpNavigator navigator = HelpNavigator.Topic;
System.Windows.Forms.Help.ShowHelp(this, "x.hlp", navigator, "906");
But the above code is not poping up anything..
Can anyone plz help me..
Thanks
Sudhakar
|
|
|
|
|
As I mentioned before, the help classes in .NET only work with HTML Help 1.x files (.chm). If you want to open a WinHelp file (.hlp), you should P/Invoke the WinHelp [^]:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern bool WinHelp(
IntPtr hWndMain,
string lpszHelp,
[MarshalAs(UnmanagedType.SysUInt)] IntPtr uCommand,
[MarshalAs(UnmanagedType.SysUInt)] IntPtr dwData); The last two params are processor-dependent types, which is why they are defined each as an IntPtr . To pass these values correctly, you'd use whatever int or long (doesn't really matter) and pass them to the constructor for the IntPtr like so:
IntPtr param1 = new IntPtr( 1); This doesn't make a pointer to one - just wraps the value 1 in a processor-dependent integer. This is for portability on 32- and 64-bit processors (something a lot of examples fail to take into account).
You can find the enum constants (and what to pass into dwData depending on the constant used for uCommand ) in the documentation for the WinHelp function at http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/functions/winhelp.asp[^]. These constants are defined in WinUser.h in the Platform SDK (installed by default with VS.NET).
Microsoft MVP, Visual C#
My Articles
|
|
|
|