|
I got a gridview with 12 unbound columns that is gonna be exported to Excel document. The exporting is already done but here is where im failing. Some cells can be empty in the gridview and trying to get its value will result in error: "Object reference not set to an instance of an object". Value property doesnt even seem to exist if its an empty cell.
This is how i do it now. Im sending the gridviews rowcollection to the method that exports it to excel. There i get the value from a cell with rows[index].Cells["columnname"].Value. Temporarily fixed it now with a try catch for every column as i got tired of it, but there must be another way.
|
|
|
|
|
I just did this a couple of days ago. Check for rows[i].Cells[j].Value == null. If my whole row is null I don't send that row since the gridview automatically creates the row and I may not have used it. Otherwise, set the data for that cell to "" so it doesn't cause an error.
string getCellValue(int row, int cell)
{
string rtn = "";
if (dataGridView1.Rows[row].Cells[0].Value != null) {
rtn = dataGridView1.Rows[i].Cells[0].Value.ToString();
}
return rtn;
}
But I like this better
string getCellValue(DataGridViewCell cell)
{
return (cell.Value != null ? cell.Value.ToString() : "");
}
SS => Qualified in Submarines
"We sleep soundly in our beds because rough men stand ready in the night to visit violence on those who would do us harm". Winston Churchill
|
|
|
|
|
I am creating a program that will simulate the functions of a robot by parsing a log file created by another program for a school placement. The problem here is I'm not really a programmer, I am a hardware/network guy but they assigned me this task anyways. If anyone can help with some resources that would help me out with this would be grateful.
|
|
|
|
|
There are many tool available in the market to read the log files.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
What format are your log files in, do you know? By that I meant do you know what program wrote them? or where they handwritten so to speak? If manual, do they follow a schema? (I'm thinking XML here)
|
|
|
|
|
The log is actually not really a file but created in ram and shown in a console like interface. However, I am not getting into that mess and have decided that the process to get the simulation running would be done by simply copying the log and pasting into a notepad document and saving. Short answer: txt. The logs are very structured and follow strict set of rules. I made a short set of instructions and this is what was spit out:
D 10:44:57 Starting program "Prog1" (lines 1 to 5)
A 10:44:57 initializing instrument
E 10:44:57 Line 1 : Dispense
tip 1 : dispense 0.00nl 1, 1 Deep Well, landscape [1,1]
10.00µl ">> Water << 23" Fixed <3 - 50µl> Single
E 10:44:59 Line 2 : Aspirate
tip 1 : aspirate 0.00nl 4, 5 Deep Well, landscape [1,2]
0.00nl "Water" Fixed <all volumes> Single
E 10:45:01 Line 3 : Aspirate
tip 1 : aspirate 10.56µl 4, 4 Deep Well, landscape [1,2]
10.00µl "Water" Fixed <3 - 50µl> Single
E 10:45:03 Line 4 : Dispense
tip 1 : dispense 20.56µl 6, 3 Deep Well, landscape [1,1]
10.00µl ">> Water << 23" Fixed <3 - 50µl> Single
E 10:45:05 Line 5 : Wash Tips
wash (2ml + 1ml), grid 20 and grid 20
|
|
|
|
|
To do it in a hurry, just infer what it looks like and parse it manually. If you want a more robust solution, write out a formal grammar for it, and use something like Percenburg Grammatica.
Theres another nice one whose name escapes me, which is used declaratively instead of using a grammar file and codegen. Argh. Ahah. Irony. Thank you CP search :P
|
|
|
|
|
Sorry about that. Time difference and everything.
Do you have a formal structure for it? If you do, its real easy to translate that into an XSD (XML Schema Document) after which you'd write a DOM parser (there are lots of free tools that can do it for you so you don't have to muck around with actually writing the parser), if you don't then there's no easy way about this and you're going to have to write your own parser.
|
|
|
|
|
|
|
|
I don't know about anybody else, but I use a transparent Panel to select the area of the screen to capture, then:
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap
(
this.pPanel.Width
,
this.pPanel.Height
) ;
using ( System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage ( bitmap ) )
{
gr.CopyFromScreen
(
this.pPanel.PointToScreen ( new System.Drawing.Point ( 0 , 0 ) )
,
new System.Drawing.Point ( 0 , 0 )
,
this.pPanel.Size
) ;
try
{
System.IO.StreamWriter sw = new System.IO.StreamWriter
(
new System.IO.FileStream
(
this.dlgFileSave.FileName
,
System.IO.FileMode.Create
,
System.IO.FileAccess.Write
,
System.IO.FileShare.None
)
) ;
bitmap.Save ( sw.BaseStream , System.Drawing.Imaging.ImageFormat.Png ) ;
sw.Close() ;
}
catch ( System.Exception err )
{
System.Windows.Forms.MessageBox.Show
(
"Could not open file\n" +
err.Message
,
"File open error"
,
System.Windows.Forms.MessageBoxButtons.OK
,
System.Windows.Forms.MessageBoxIcon.Exclamation
) ;
}
}
|
|
|
|
|
|
You don't - if you didn't get an answer you're happy with, then you probably won't get a better one this time around
|
|
|
|
|
|
And what if I started a discussion, and made some progress since and want to ask further related question? what would you suggest?
|
|
|
|
|
If you reply to someone, they'll get an email notifying them of the reply.
If you've got a whole new question to ask, then it's fine to post this as a new thread - it's mostly protection against the idiots who post stupid / impossible questions, and would just constantly bump their thread to the top if given the chance (they already try reposting the same question over and over, but that's easier to ignore)
|
|
|
|
|
By bouncing do you mean stopping a service/thread and then restarting it?
If no, then you need to explain what bounce is.
If yes, then if you're momentarily halting the thread, like pressing the pause button, then you could use Thread.Sleep()/Interrupt()/Join(), more on that here: http://msdn.microsoft.com/en-us/library/system.threading.thread_members.aspx[^]
If you mean pausing the application mid activity and then closing it and once the application is run again you would expect the system to pick up from where you left off, you'll need to save state and that would at the least require serialization.
|
|
|
|
|
I think he means "bump" a thread as in a forum post. As in bring it back to the top. As in the thing we hate and pour scorn on whoever does it.
|
|
|
|
|
Ah!
<Padawan mode on>
I'd like to see him try
<\Padawan mode on>
|
|
|
|
|
My device has 4 inputed of capture intend that my application communicates with the device,
to visualize the 4 videos and to record.
Alex(alex_xso@hotmail.com)
|
|
|
|
|
Alex_xso wrote: My device has 4 inputed of capture intend that my application communicates with the device,
to visualize the 4 videos and to record.
OK, so where is the problem?
Also, do you have drivers? API to deal with the video capture device?
|
|
|
|
|
|
I have developed a simple client/server app which echoes whatever text the clients sends to the server.
Currently, it echoes text only to one client, which has send the text, but I want it to send to all the clients connected.
The problem is that when one client writes to the server after that the client waits for receiving and as soon it has received the echo it starts writing to the server, so if some other client sends to the server, and the server echoes back to all the clients, only those will receive the message which are waiting for reading, but none are except the client which has send the message to the server.
So how to overcome this?
Btw, it is a console application, is it possible to do in it?
I guess I explained it correctly. If not, then please ask again
modified on Monday, January 26, 2009 9:59 AM
|
|
|
|
|
It sounds like you're trying to emulate a group chat/IM session.
You're going to need to register all the users who "log" on to your server and are interested in the echo. The Observer pattern is precisely what you are looking for: http://www.dofactory.com/Patterns/PatternObserver.aspx[^] and http://en.wikipedia.org/wiki/Observer_pattern[^]
After reading that you should have a clue of what you ought to do but in plain English what you're doing is that you're making a list of all the registrants and instead of echoing to one, you're broadcasting the echo to each and everyone in the list.
Post back if you need more help.
|
|
|
|
|