|
To add on to Christian reply, your string might contain alphabets or non-digit characters. Perhaps you can run a Char.IsDigit(..) check on each characters in the string.
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
How do I handle empty strings in this particular code, I will really appreciate it.
Thanks,
ZIndagi
ZIndagi
|
|
|
|
|
This handles an empty value:
int OnHandVar1;<br />
if (OnHandRow1.Text.Length == 0) {<br />
OnHandVar1 = 0;<br />
} else {<br />
OnHandVar1 = int.Parse(OnHandRow1.Text);<br />
}
If the value is not empty and not numeric, it still gives an error, though.
---
b { font-weight: normal; }
|
|
|
|
|
is there a simple way to change background color of the row, based on its value...(based on cell value in same row)
|
|
|
|
|
"Simple" is a relative term, dependant on your definition and programming skill level, compared to someone else.
You might want to take a look at this[^] article by Piero.Viano.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi there friends,
I am working on a program that its language is not english(so mine!).
every time user wants to change the language he must press ALT+SHIFT
and this is annoying.How can I change language programatically?
Thank You!
|
|
|
|
|
i have a problem where, i need to display shared folders of a specified computer in a explorer. If i give a computer name, it should display the shared folders in a explorer. I could do that through wmi queries, but it is in not explorer view. The problem has to be solved in C#.
can anybody guide me?
Amar
|
|
|
|
|
I have binary files that have delimiters inserted to indicate document breaks. I need to break apart these files into these documents in C# and save each to a binary file. How would one go about this?
|
|
|
|
|
Leo,
To do this task, if your files are binary to begin with, you will need to use this code snippet to read the file :
System.IO.FileStream <name of="" variable=""> = new System.IO.FileStream("<name of="" file="">", FileMode.Open)
System.IO.BinaryReader <name of="" variable=""> = new System.IO.BinaryReader();
That will open the document for binary reading.
To read the document and convert it to a string for splitting, add this. (br will be used for the BinaryReader)
string <name of="" string=""> = "";
foreach(byte data in br.ReadBytes((int)fs.Length))
{
<name of="" string=""> = <name of="" string=""> + new String(data);
}
string[] <name of="" array=""> = <name of="" string="">.Split("<delimiter>".ToCharArray());
That seperates the string into an array so you can write the data with this:
This is setting up the writer from a Windows forms SaveFileDialog:
for(int i = 0; i <= this.saveFileDialog1.FileNames.Size; i++)
{
BinaryWriter[] bw = new BinaryWriter(new FileStream(this.saveFileDialog1.FileNames[i], FileMode.Create))[this.saveFileDialog1.FileNames.Size];
}
Now to write the individual data:
for(int i = 0; i <= this.saveFileDialog1.FileNames.Size; i++)
{
bw[i].Write(<name of="" array="">[i]);
bw[i].Close();
}
And that should do it.
Mike Stark
|
|
|
|
|
I want to know how to check the internet port status, becuse i want to create a TCP server application that can select the port dynamic, you know not static.
For example i want to check port 1313 from ip 127.0.0.1, i want to know status (is it opened or not), if opened i want to know who is open the port. Like port scanner you know, but this for socket application.
Thank's for your comments.
|
|
|
|
|
The only thing I can think of is that you try to programatically open ports in a while loop which has a try-catch inside to try to open the socket, and catch the exception and continue the loop...You can also figure out which specific exception will fire when the port is in use and only catch that one, but let other exceptions be thrown or just catch-all and assume that it's an already open-port.
|
|
|
|
|
|
I am working on a project and need the communities help. I have searched extensively, and cannot seem to find a solution to this problem.
I need to create a very simple properties grid. It should have no headers, and simply display 2 columns with name/value pairs listed one per row.
I have created this control by deriving a custom control from the DataGrid object, and it works well, except for one thing. The columns are not resizable without including a header column to the grid.
What I need to do is be able to resize the columns by clicking on the divider between the two cells on any row of the grid. This is the same behavior as what you see in the PropertiesGrid control.
Does anyone have any suggestions on how to implement this? It seems like this should not be hard to do, yet I have been unable to find any reference on where to even begin, much less an implemented solution to this problem.
Thanks in advance for everyones time.
Scot.
|
|
|
|
|
i have some piece of info which might get you further but it's for resizing columns according to the header text size.
piece of code is:
MethodInfo methodInfo = datagrid.GetType().GetMethod("ColAutoResize", BindingFlags.NonPublic | BindingFlags.Instance);
if (methodInfo == null)
return;
for(int i=0; i
|
|
|
|
|
Hi, I want to solve this problem, maybe yu can help me.
I have a lisview with filters, when perm any filter I clear an fill the listview with the filterde rows, the problem is when I have my lisview scrolled horizontally to the right and perform a filter, the listview scroll is moved to the left again to the star of the listview, I dont want this I wat the lisview mantain its scrolled position.
Thank you!!!!
Another question:
When I have both vertical and horizontal scrolls and clear the listview items, what happans with the horizontal scroll (vertical scroll desapear and listview resize (I think)). Resize? Move? and the lisview??
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hi.
The only way I see without using unmanaged code is to not clear the listview but modify the ListViewItem s to reflect the new data.
When you remove a ListViewItem , the ListView has to check whether the remaining items can be displayed with or without scrollbars, so when you remove all items (clear the LV), then there will be no scrollbars at all, because 0 items will occupy no space.
Perhaps you could remember the scroll position and restore it afterwards, but that will include using P/invoke.
Regards,
mav
|
|
|
|
|
Hello all,
I've noticed an "interesting" behavior in winforms. If I have a custom control whose paint event is overridden to draw a gradient background. When the control is docked and I try to create a LinearGradientBrush by specifying colors and a rectangle, I get an Out of Memory exception. OutOfMemoryException is the most useless exception type, because it does not allow you to fix or even diagnose problems in your code. You are simply screwed as far as I can tell.
Does anybody have an idea why this happens when the control is docked, but does not occur at any other time (like when the control is anchored to achieve the same effect)?
Will
|
|
|
|
|
I guess you should verify the dimensions of your rectangle in either case...
Regards,
mav
|
|
|
|
|
|
That's possible. I didn't unit test that code as thoroughly as I should have. I was thinking it was something like running out of a handle, which didn't make sense at all. I'll have to check that when I get home tonight.
That still doesn't explain what would cause the problem to occur only when the control is docked. Any ideas?
Will
|
|
|
|
|
From personal experience, exhausting the handle pool will generate OutOfMemory exceptions. This can easily happen if you grab a Graphics object and don't Dispose it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Does this mean I should worry about re-entering the paint method of my form? In other words, can it be called from multiple threads (I would think not, since the message loop is single threaded)?
So far, I've been having problems on the first attempt at painting, so I doubt that I am overallocating GDI objects. I also use the using statement religiously. I am creating a graphics object in the background however, to enable double-buffering - I'll check that as well.
Will
|
|
|
|
|
gantww wrote:
Does this mean I should worry about re-entering the paint method of my form?
If, by this, you mean that your Paint method is calling itself, you've got huge issues. Paint should never call itself recursively.
gantww wrote:
In other words, can it be called from multiple threads (I would think not, since the message loop is single threaded)?
You should NOT be doing this. You can invoke an Invalidate call back on the UI thread, but you should NEVER make a direct call from a thread to a forms Paint code. Bad, and unpredictable, things will happen.
gantww wrote:
I am creating a graphics object in the background however, to enable double-buffering -
You're what? Are you saying that you're creating a Graphics object on a background thread? Bad idea! Graphics objects should only be created on the thread that created the control your painting.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Uhh. I was running real low on caffeine when I wrote the above statements. Let me rephrase them. I'm creating a graphics object in paint and drawing to a bitmap first (in many cases, anyway) and then painting that bitmap onto the form using the graphics object provided by the event handler. I'm not invoking the paint event from multiple threads or recursing it - I'm wondering if there is any way that windows (or the development environment) could be doing something like that behind my back. I'm particularly concerned that it may be occurring while I'm debugging the code (I'm using dual monitors, so I don't have all the problems of debugging paint code).
By the way, I checked my code and I was able to reproduce the issue where a colorblend was not ending with 1.0. My calculations were off very slightly. I'm hoping that will fix the issue.
Thanks,
Will
|
|
|
|
|
gantww wrote:
I'm wondering if there is any way that windows (or the development environment) could be doing something like that behind my back.
No chance.
gantww wrote:
By the way, I checked my code and I was able to reproduce the issue where a colorblend was not ending with 1.0. My calculations were off very slightly. I'm hoping that will fix the issue.
More than likely.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|