|
I have an event that needs to occur every time a file containing records is imported, I keep getting an exception at this line:
OnImportFile(this, new ImportFileEventArgs(fi.Length, i, fi[i].Name));
The exception is "Object reference not set to an instance of an object."
I have check to make sure none of my variables are Null, I don't know what the deal is. Suggestions Please?
J.Perez
|
|
|
|
|
Justin Perez wrote: I have check to make sure none of my variables are Null, I don't know what the deal is.
You just explained what the deal is, then you tell us you don't know what the deal is.
Perhaps you are not explaining yourself very well.
Justin Perez wrote: OnImportFile(this, new ImportFileEventArgs(fi.Length, i, fi[i].Name));
TIP: Don't put all this stuff in one line of code. It makes the code difficult to read, and difficult to debug.
Change it to:
int length = fi.Length;
FIClassName currentFI = fi[i];
string fiName = currentFI.Name;
ImportFileEventArgs(length, i, fiName);
That makes it a lot easier to debug and step through and see where all the values are and how it is being built up.
|
|
|
|
|
Is anything actually assigned to handle the OnImportFile?
someObject.OnImportFile+= new OnImportFileEvent(someHandler);
If not, you will get an exception Take this example code
<br />
class Program {<br />
static void Main(string[] args) {<br />
someClass obj = new someClass();<br />
obj.RaiseEvent();<br />
obj.someEvent += new someClass.SomeEvent(EventHandler);<br />
obj.RaiseEvent();<br />
}<br />
static void EventHandler(object sender, EventArgs e) {<br />
<br />
}<br />
}<br />
class someClass {<br />
public delegate void SomeEvent(object sender, EventArgs args);<br />
<br />
public SomeEvent someEvent;<br />
<br />
public void RaiseEvent() {<br />
someEvent(this,new EventArgs());<br />
}<br />
}
You can resolve this by testing someEvent for null
<br />
public void RaiseEvent() {<br />
if(someEvent!=null)<br />
someEvent(this,new EventArgs());<br />
}<br />
or setting it to have at least one handler when you create the object
<br />
class someClass {<br />
public delegate void SomeEvent(object sender, EventArgs args);<br />
<br />
public SomeEvent someEvent;<br />
someClass{<br />
someEvent+=new SomeEvent(internalHandler);<br />
}<br />
private void internalHandler(object sender, EventArgs e) {}<br />
public void RaiseEvent() {<br />
someEvent(this,new EventArgs());<br />
}<br />
}
I usually test for null, but either works.
|
|
|
|
|
bearfx wrote: Is anything actually assigned to handle the OnImportFile?
someObject.OnImportFile+= new OnImportFileEvent(someHandler);
I didn't not have anything assigned to handle OnImportFile. I am new to events so bear with me here Below is my delegate and event in my class.
public delegate void GNISImportFileEventHandler(object sender, ImportFileEventArgs e);
public event GNISImportFileEventHandler OnImportFile;
So to assign something on handle OnImportFile I have this:
OnImportFile += new GNISImportFileEventHandler(OnImportFile);
From the articles I have been reading that should do the trick, but I get the exception "Delegate to an instance method cannot have null 'this'." A article that covers this issue would be greatly appreciated.
|
|
|
|
|
How do I disable the Next button on the Custom Setup screen if no features is selected?
thanks !!!
|
|
|
|
|
Have a look at Enabled property of a button
|
|
|
|
|
omg,
where is it?
i cant find...
|
|
|
|
|
|
Hello there
I've put dataGridView control on the Form and i've written this code:
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
dataGridView1.Columns.Add("Main", "Main");<br />
dataGridView1.Rows.Add(3);<br />
<br />
dataGridView1[0, 0].Value = "A";<br />
dataGridView1[0, 1].Value = "B";<br />
dataGridView1[0, 2].Value = "F";<br />
dataGridView1[0, 3].Value = "ABC";<br />
}
So, when i try to sort it (clicking on the header of the table) - the last row ("ABC") is every time the last
You can go a long way with a smile. You can go a lot farther with a smile and a gun. (C) Al Capone
|
|
|
|
|
Hi,
Make number of row 1 more then acutal rows.
dataGridView1.Rows.Add(4)
I think internally it take the last rows as newRow and doesnot considers while sorting.
Hope this helps.
Regards,
Anil Ch
|
|
|
|
|
Hello everyone,
The Windows Application that I am working on requires displaying some data which are stored in a remote database server. The user can get connect and import the data into the application and then get disconnected and continue working. The Windows Application requires having similar ability to the database server as it needs to run queries on the Data.
I have tried the following approaches and ended up with some problems.
The first approach was to load the data into a DataGrid and then use filters on the DataSet to run queries. Unfortunately, I need to display the filtered data in different manner than DataGrid and I was unable to do so. I need to display the filtered data in number of TextBoxs and not in the DataGrid. Sadly, I was not able to do so unless I am missing something here!
The second approach was to download the data into a CSV file and then use combination of StreamReader and StreamWriter to run query on the CSV file and achieve what is needed. Sadly, the speed that I can run query is very much dependent on the size of the CSV file. Unless I am missing something here too!
My question is, what is the best way to import data from a remote database server and have the ability to run query and display the result in a fashion that I desire (in various TextBox)?
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
Do you need to have the data imported from SQL server accessable only in the active session or have them for later processing too?
In first case you can store the data in a DataTable object (in memory), apply filters on it and take out any data from the Rows[ItemNo] object to feel your TextBoxes.
In the second case you can establish connection to some local data store like FoxPro dbf files or Access mdb, store your data there and then use all index search advantages to execute your tasks.
Tell me, why do you need to process data offline?
|
|
|
|
|
the code of Ant on a Chessboard please...
|
|
|
|
|
Write it yourself, or Google for it. All you have to do is type "ant on a chessboard" into the search box.
If you wanted help writing it yourself, ask specific questions about where you're getting stuck. Just comming here asking for the code will only be met by replies with a flamethrower.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Sorry, I don't have it lying around, but I have the code for Troll in a Forum
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
what does this mean - "Black holes are the places where God divided by 0..." ??
Blumen
|
|
|
|
|
M.omar wrote: the code of Ant on a Chessboard please...
Don't have that but here is the code for Loser on a Forum
static public class FlameThrower<br />
{<br />
public static void throwflames()<br />
{<br />
Console.WriteLine("LOSER");<br />
}<br />
}<br />
led mike
|
|
|
|
|
|
Hey guys,
Im in the process of creating a 1941-type shooter set in outer space. I have a simple jpeg of distant stars I wanted to set as the background. How can achieve this? And if possible, how can I make it scroll as if my spaceship appears to be moving?
Thanks for any help.
|
|
|
|
|
That's going to be a problem. A scrolling background on a Windows form means that the background will be redrawing every time the image scrolls even one pixel. That will also force a redraw of every control on the form. The more controls you have, the more time it takes to generate a single frame in your game.
The best solution you have is to use DirectX. But, that would require a complete rewrite of your game. You might want to look into Microsoft's XNA Developer's Center[^] first.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
In 2D Games with the tpye you want:
1) There is a screen size background image and you draw onto a part of this big background image and update(Invalidate) just that part so because the user does see only a small portion of the big background image, he thinks he is moving in some directions
2) Have a look at Code4Fun web site, where you can find some tutorials on game development.
Hope this helps...
|
|
|
|
|
I want to allow users to create filters by typing in a textbox the filter they wish to apply to any particular column. I want to apply the filter as the user types it, and I want to apply it as if the displayed value were a string. For example, if I have data with numbers 0-23 associated with it, and a user types the number 1, all data with numbers 1 or 10-19 should still be displayed. So essentially, I want to apply the filter expression "[ID] LIKE '1%'", but when I do this I get the error "Cannot perform 'Like' operation on System.Int64 and System.String". How can I prevent this error without making the filter string something like "[ID] = 1 OR ([ID] >= 10 AND [ID] < 20) OR ([ID] >= 100 AND [ID] < 200) OR ..." (because that would get out of hand)? (I also posted this in ADO because I don't really know where it belongs) Thanks.
-Jeff
|
|
|
|
|
What's the data source you're using? If it's not a database souce, like an Access or SQL database, you can't do filtering. Filtering does not work on every data source, like arrays or lists. You can check the SupportsFiltering property of your BindingSource object to see if the datasource supports filtering.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Its a database. The same code works if the type of column ID is string.
-Jeff
|
|
|
|
|
OK. Well, you can't do a LIKE on a number, not even in SQL. If you were to allow LIKE operations on any field, you'd have to retrieve the data from the database, having it convert all the numeric fields to strings before they get sent to your DataSet. THEN, you can do a LIKE filter on it.
Of course, the problem becomes writing that data back to the database if there are any changes to it. You'd have to have a stored procedure convert the "string" data back to their appropriate data types in the INSET and UPDATE queries.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|