|
ok solved it. had to use enqueue and dequeue. thanks
|
|
|
|
|
Hi,
How to generate only 0's and 1's by loop through the condition. I have tried with Random Class like
private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
Inside for loop i am having the following line;
int returnValue = RandomNumber(0, 1);
It's returning all 0's. Is any other method to use.
Thanks,
Subbu
|
|
|
|
|
Use
int returnValue = RandomNumber(0, 2); because it generates random numbers excluding the max
|
|
|
|
|
Thanks a lot Anindya.
One question. Is it possible to get 0's and 1's sequence (01010101010101...) like this?
|
|
|
|
|
Create a StringBuilder object. Append that random number to the object in an iteration. After desired iteration just use ToString() method of StringBuilder object and it will create a sequence like that.
Thanks
|
|
|
|
|
spalanivel wrote: private int RandomNumber(int min, int max) {
Random random = new Random();
return random.Next(min, max);
}
Don't create Random objects all the time, it makes no sense, since the Random class guarantees Next() will generate random numbers INSIDE a Random object, not AMONGST different Random objects. Instead create your Random object once, and keep a reference to it as a class member.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Suppose I have the following class :
public class A
{
public bool Boolean {get; set;}
public List<B> ListOfB {get; set;}
}
public class B
{
public String StringValue {get; set;}
public List<String> OneList {get; set;}
public List<String> AnotherList {get; set;}
}
I want to expose the class A and under it the B class in a propertygrid. I have tried a lot of thing, but no help. May be I am missing something. What I did is as follows :
[DefaultProperty("ListOfB")]
public class A
{
[Browsable(false)]
public bool Boolean {get; set;}
[Category("Visuals")]
[Description("YZYZYZ")]
[MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Localizable(true)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[Editor(typeof(BListEditor), typeof(UITypeEditor))]
public List<B> ListOfB {get; set;}
}
public class B
{
public String StringValue {get; set;}
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[Category("Visuals")]
[Description("XXYZ")]
[MergableProperty(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<String> OneList {get; set;}
[Description("PPPWRT")]
[MergableProperty(true)]
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
[Category("Visuals")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<String> AnotherList {get; set;}
}
public class BListEditor : CollectionEditor
{
public BListEditor()
: base(typeof(List<B> ) )
{ }
protected override Type[] CreateNewItemTypes()
{
return new Type[] {typeof(B)};
}
protected override object SetItems(object editValue, object[] value)
{
A settings = (A)Context.Instance;
object ret = base.SetItems(editValue, value);
return ret;
}
}
I have tried that but no luck. The propertygrid can take the value in collection editor but can't able to store the value. After inserting one B item taking all the data when you click OK nothing actually being inserted into the List of B in class A.
Please help me out.
Thanks in advance.
|
|
|
|
|
It sounds like the ExpandableObjectConverter might be what you need. You can look that up on MSDN, or Google for it (you'll get lots of hits).
Take a look at Add Custom Properties to a PropertyGrid[^], it shows several methods to get what it sounds like you want to do.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
Hi Forum,
I have to open a text file in c# and read few lines and then I need to update some lines in the middle of the file.
Let me tell you what am I doing. Here in my program I open a file and display it in a RTF control. I have provided one button to insert one selected character to recognize updation. Now if user clicks somewhere in the rtf control and click to that button, it should insert the selected character to that cursor position. This is same as we insert Emotion symbols here in this forum.
That character can be inserted anywhere in the file.
Please tell me how can I insert a character to a particular cursor position.
Thanks ......
Vishal Moharikar.
|
|
|
|
|
OK so what you want to do is add a character to the selected position is the richtextbox and then save the data back to the file?
to insert into richtextbox...
RichTextBox1.Text.Insert(RichTextBox1.SelectionStart, ":)");
...you should also check the length of the current selection and remove that first if greater than 0
then you just save you text back to the file, which I will assume you can attempt as you have managed to read from the file
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hello Musefan
Thanks for your kind reply. but its not helping me.
Just to see what happens;I used this :
string str = RichTextBox1.Text;
int icurpos = RichTextBox1.SelectionStart;
RichTextBox1.Text = str.Insert(icurpos,"a");
and you suggested me :
RichTextBox1.Text.Insert(icurpos, "smile");
I don't think that there is any difference between above two code blocks. But still behavior is simply different. First one works but not second. I am new to C# and find myself unable to find out the reason.
Secondly when I use the first code block, after inserting desired character at the right place cursor moves to the first character in the rich edit control.
I hope I made my view very clear. Please give any suggestion to resolve the problem.
Thanks in advance.
Vishal Moharikar.
|
|
|
|
|
Sorry, bit wrong...
RichTextBox1.Text = RichTextBox1.Text.Insert(icurpos, "smile");
RichTextBox1.SelectionStart = icurpos + "smile".Length;
RichTextBox1.SelectionLength = 0;
...that should work better
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi Musefan,
Thanks a lot. I think you gave me enough solution.
Thanks once again and sorry for a late reply.
Thanks.
Vishal Moharikar
|
|
|
|
|
Hi folks,
some items in checkedlistbox for example the item will be like this (Kishore) kishore@gmail.com
i had a string kishore@gmail.com i have to compare this string with the item in checkedlistbox i have completed this but iam getting a error
"List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change."
Code:
if (checkedListBox_MailLst.Items.Count > 0)
foreach (string item in checkedListBox_MailLst.Items)
{
string mailItem=item;
checklistItem = mailItem.Split(' ');
foreach (string mailId in myMail)
{
if (checklistItem[2].ToString() == mailId)
if(checkedListBox_MailLst.Items.Contains
(mailItem))
{
int selectedItemIndex = checkedListBox_MailLst.Items.IndexOf(mailItem);
checkedListBox_MailLst.SetItemCheckState(selectedItemIndex, CheckState.Checked);
}
}
}
|
|
|
|
|
You can't modify what you're enumerating over. If you think about it, and the possible disasterous results if you could, it makes sense!.
What you can do is flag or store whatever needs modifying, and do the change afterwards. If you no longer need to keep testing, you can use break to exit imediately.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
0. Remove the email address from your example unless you really *like* special devices for the decerning gentleman.
1. Compare strings using string1.Equals(string2) , string1 == string2 is just comparing that the objects are the same (the same reference) not that the contents are the same.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hello all,
I am trying to develop an application which will record user login information in a database at the time any user logs into the system that is connected in a network (basically a LAN network, the information will be stored at the server).... his details like user name and login time will be fetched from registry details i suppose..... but i am not able to figure out a way of getting those events and locations in the registry using C#.net....... i believe i need to create a service application for this(as there won't be any interaction with the end-user) but i am quite new to these kinds of technologies........ For the past couple of days i have been searching on net for some articles related to design services and fetching such values in .net. but haven't got any simple documentation !!!!
Please help me with this in understanding the concept step by step as this is quite an urgency for me....... your help is heighly awaited
Thanks
Sujay
|
|
|
|
|
To create a service, just use the wizard of Visual Studio.
For example, you are creating MyService.exe. After compiling, you can install it using "installutil MyService.exe".
Then you can start/stop/restart it in service window. To uninstall it using "installutil /u MyService.exe".
To get user information, use : Environment.UserName
|
|
|
|
|
I have a .exe file which i need to run before my application got loaded,
So i am using Process class. Creating new process and running this exe and after this running my application.
I have few question :
a)Can we embed an .exe file in our Application(exe) file, and run that from inside? If yes, then how?
b)When we create setup project, there we specify "which files we put where", like in system folder, program folder etc. But i want to put a file inside driver folder present in system32 folder. how can we do this?
A detailed article would be great. I read/googled few article but they are not that in detail. Or i unable to search good one
c)How can we manipulate registry in setup projects, related to setup and deployements?
I am using vs2003, c#.
regards
|
|
|
|
|
a) I fear there is not an easy way to do this. You can try to add the exe to the project as a biinary resource, then, at runtime, write it in a temporary folder and execute it using Process.Start.
b) In the File System Editor of your setup project, right-clicking on "File System on Target Machine", you can select Add Special Folder->System Folder.
c) Setup projects have a Registry Editor that can be used to write registry keys during setup.
|
|
|
|
|
Mirko1980 wrote: I fear there is not an easy way to do this. You can try to add the exe to the project as a biinary resource, then, at runtime, write it in a temporary folder and execute it using Process.Start.
Whats the use if i had to copy it temp folder, at present i am putting it inside setup and while installation it installed in program's folder. from there i am running it using Process. start, same?
Mirko1980 wrote: In the File System Editor of your setup project, right-clicking on "File System on Target Machine", you can select Add Special Folder->System Folder.
I am putting my files successfully up to here, but ii want to put inside driver folder which is present inside Environment.SysytemDirectory
any way to do this?
Mirko1980 wrote: Setup projects have a Registry Editor that can be used to write registry keys during setup.
Quote Selected Text
I know they have, what i want detail topic/article on it?
regards
|
|
|
|
|
a) It's not the same, but you are doing it the right way. I tought you wanted to embed an existing executable into yours.
b) Just add a directory called driver under the System one. If this directory exists, the setup will copy filed into it.
c) Well is not difficult: you add keys and value in a tree view just like you do for the file system.
In any case, there is a Code Project article on how to create setups.
|
|
|
|
|
Just joking,
Are you planning to plant a virus??
|
|
|
|
|
Hi,
In Windows form when i say FormBorderStyle as None it is not showing it in task bar. How can show it in task bar?
|
|
|
|