|
Hi,
some facts that may help you:
DateTime.Now.ToLongDateString(); returns the current date in a format corresponding to
your regional settings
DateTime.Now.ToString("some format specifier"); returns the curr date in the specified
format
if Text is a string then Text.ToString() is exactly the same thing as Text
and of course PIEBALD is right, when storing a date in a database or file you should
use a standard format, independent of regional settings.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi,
I have a question regarding abstract methods
if i place an abstract method in non abstract class what will happen if i doesnt implement that method in derived class
Any updates would be appreciated
Thanks
Thanks
Mukkanti
|
|
|
|
|
mukkanti007 wrote: if i place an abstract method in non abstract class
You can't. It breaks the semantics of being abstract.
|
|
|
|
|
If the class contains an abstract member, then the class must be marked abstract.
|
|
|
|
|
mukkanti007 wrote: if i place an abstract method in non abstract class
Not possible.
If you want a method that is optional to override, you should make it virtual. The base class has to have an implementation of the method, but you can just throw an NotImplementedException exception in the method.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Am suffering brain melt
Just in a bog-standard C# Windows App.
Could anyone show me how to get the DataGridView to actually show my values please?
I thought this code would work but it shows no values in the grid.
DataGridView dataGridView1 = new DataGridView();
BindingSource bindingSource1 = new BindingSource();
dataGridView1.AutoGenerateColumns = true;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
bindingSource1.DataSource = myHashtable;
dataGridView1.DataSource = bindingSource1;
myHashtable has 129 rows and 2 columns.
Thanks in advance.
I still remember having to write your own code in FORTRAN rather than be a cut and paste merchant being pampered by colour coded Intellisense - ahh proper programming - those were the days
|
|
|
|
|
No Problmes. It is working .... and should work at yourend too
B O N D
|
|
|
|
|
Can you see any datagrid at all? I do not see line where you add dataGridView1 to Controls collection. Just a hint.
|
|
|
|
|
Hi,
Can anyone tell me how to populate a Property Grid with data from XML file?
Thanks
|
|
|
|
|
|
hi everyone!
i would like to do the following task:
i do have a string and want to divide it into parts
e.g. "test me for more tests to get the test results after having completed the test task" should be divided up into
"test me for more"
"tests to get the"
"test results after having completed the"
"test task"
The string.split() functions splits by characters, but i want to split a string by word or even a whole line without having to parse the string line by line to divide it up.
e.g.
"test me for more tests to get the test results after having completed the test task
next one: test me for more tests to get the test results after having completed the test task
and again: test me for more tests to get the test results after having completed the test task"
should be divided up (by "test me") into
"test me for more tests to get the test results after having completed the test task next one:"
"test me for more tests to get the test results after having completed the test task and again:"
"test me for more tests to get the test results after having completed the test task"
does anyone of you know a good way how to do this?
so some kind of tokenizing like in C and C++ would be interesing. but is there something similar in C#? because in C and C++ you are able to divide strings by a token into substrings.
thanks.
stephan.
|
|
|
|
|
string.split also lets you give it a string array parameter, and it will split it everywhere it finds the string(s).
example:
<br />
string x = "test: this string should be split on every occurance of the word test!";<br />
string[] xSplit = x.Split(new string[] { "test" }, StringSplitOptions.None);<br />
<br />
for (int i = 0; i < xSplit.Length; i++)<br />
{<br />
xSplit[i] = "test" + xSplit[i];<br />
}<br />
after x.Split, xSplit will have the following strings:
[0] - ": this string should be split on every occurance of the word "
[1] - "!"
because the delimiting string gets removed.
After the for loop, it will have:
[0] - "test: this string should be split on every occurance of the word "
[1] - "test!"
which I think is what you are looking to do!
|
|
|
|
|
one correction...if the string you are splitting starts with the delimiter, then remove it before doing the split...otherwise it won't work right in that case.
<br />
if (x.StartsWith("test"))<br />
x.Remove(0, "test".Length);<br />
stick that just before the line with x.Split and you should be good.
|
|
|
|
|
mmGoDLiKe wrote: otherwise it won't work right in that case
Huh? In what way?
|
|
|
|
|
If the split string starts with the delimiter, the first resulting string will be "" and the second will be everything after the delimiter. By removing that first delimiter before you split, it will avoid the initial empty string, and it will throw the delimiter back onto the first resulting string in the for loop anyway.
Arg...you need to set a flag that determines whether or not to attach the delimiter to the first string...because in the code I showed you, it always does (which might not be good if the original string didn't start with the delimiter). You can either play with it yourself or I'll post a revision in an hour or so when I have time.
|
|
|
|
|
mmGoDLiKe wrote: the first resulting string will be ""
Yes, as it should be.
mmGoDLiKe wrote: the second will be everything after the delimiter
That makes no sense and it's not what I find when I try it.
|
|
|
|
|
If you split "test splitting this line"
you will get:
[0] ""
[1] " splitting this line"
and after re-adding "test" to each one in the for loop, you will get:
[0] "test"
[1] "test splitting this line"
which clearly isn't desirable.
Here is a quick and easy function I wrote that will work better then removing and then re-adding the delimiter:
public string[] Split(string source, string delimiter)<br />
{<br />
if (source.Length <= 1)<br />
return new string[] { source };<br />
<br />
int currentPosition = 0;<br />
<br />
List<string> splitStrings = new List<string>();<br />
<br />
while (true)<br />
{<br />
int nextDelimiterPos = (source.Length == currentPosition + 1) ? -1 : source.IndexOf(delimiter, currentPosition + 1);<br />
<br />
if (nextDelimiterPos == -1)<br />
{<br />
splitStrings.Add(source.Substring(currentPosition).Trim());<br />
break;<br />
}<br />
else<br />
{<br />
splitStrings.Add(source.Substring(currentPosition, nextDelimiterPos - currentPosition).Trim());<br />
<br />
currentPosition = nextDelimiterPos;<br />
}<br />
}<br />
<br />
return splitStrings.ToArray();<br />
}
test string: "testing the ability of this function to split this test string containing test"
delimiter: "test"
result:
[0] "testing the ability of this function to split this"
[1] "test string containing"
[2] "test"
|
|
|
|
|
|
Hi,
To split string with some fixed length ex 50,
but you don't want to split the last word.
So use
string str="<some text="">";
string destString=string.empty;
While(str.Lenght> 0)
{
if(str.Length <= 50)
destString+=str;
else
{
int index= str.SubString(0,50).LastIndexOf(" ");
index=(index>0)?index:50;
destString+=str.SubString(0,index);
str=str.SubString(index+1);
}
}
Best Regards,
Chetan Patel
|
|
|
|
|
Won't string.Split(Environment.NewLine) do what you want ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You don't want Split at all because it removes the delimiter from the results and you'd need to add it back on.
You'll want to write your own version of Split that doesn't remove the delimiter.
Or wait for Microsoft to add another value to System.StringSplitOptions that causes Split to work the way you want.
|
|
|
|
|
Hi all,
I've come across an interesting problem that I'm not really sure how to get around.
I have a custom user control I designed to edit certain properties of a document, similar to the VS2005 properties area. Sometimes input needs to be validated before the user leaves a textbox, so what I did was I added an event handler to the Validate event on the individual items.
Here is my problem: the Validate event doesn't fire if you click on anything in the GUI that has "CanFocus=false." So, none of the menu strips, toolstrips, etc. cause the Validate event to fire. Neither does the Leave event or the LostFocus event.
I want it to behave the same way as the VS2005 properties window - if you are in the middle of editing a property and you click on a toolstrip button or a menustrip item, it will cancel the click and give you a validation error message. Is there any way to do this besides, say, adding a Click event handler to every control in the GUI and telling it to unfocus the property being edited?
Thanks in advance!
|
|
|
|
|
Hi there,
can a service written using C# to open(run) another application written using C# too,
In other word I wrote a service which I need to open forms and do more , so I had a windows application to perform all what all I want, but I do not know how can I call it from the service !
I hope I made my self clear and described the problem well ,
please urgent help is needed
Thanks
There is always something to learn
|
|
|
|
|
You won't see any interface if you have a service open an application. Services run on system accounts, not on user accounts, so the user would never see the open application.
If you want to control the service from a form, you can create a seperate application that configures a settings file and then restarts the service when you are finished.
If you need the application and the service to communicate in real time and relay information, then you will need to use .NET remoting or TCP for communication, or some other form of exchanging data between apps.
|
|
|
|
|
I am not sure it may be helpful for you or not. But from windows services we can open process like "notepad", write on files etc. but not fully interact with desktop.
|
|
|
|