|
draco_iii wrote:
if(time1 <= time2 <= time3)
{
The comparison of time1 <= time 2 returns a bool (if a comparable type, more on that shortly) which it would then compare that bool value to time3.
It would be
time2 >= time1 && time2 <= time3
But there is another problem, you cannot use that as comparisons for strings. You would use the string.CompareTo() with returns a int value:
< 0 : string less than target
0 : same
> 0 : target less than string
So you would have:
if( time2.CompareTo(time1) >= 0 && time2.CompareTo(time3) <= 0)
{
do...
}
Rocky Moore <><
|
|
|
|
|
I use HashTable to store some information retreived from database. In database data is stored in some particular order, that is important for the application.
When I want to display the data (loaded into hashtable) in ASPX page, user gets data _not_ in the same order as it was in the database. Is there any way to force Hashtable to return elements (via iterators) in the same order as entered [Maybe to implement some interface or sth..?]. Or maybe there is another, similar class, holding key-value pairs, that would do this for me.
Thanx for any suggestions
|
|
|
|
|
Why not stick with a DataSet or DataTable in memory, this way you could use a DataView to deal with your sorting. These structures were designed to stay up in memory anyway.
Cheers,;P
Erick
|
|
|
|
|
If for some reason you do not want to use a DataSet or DataTable as the other poster mentioned, you will have to use a combination collection. I had the same problem and solved it by deriving from an ArrayList and a private Hash table. I overrode the Add, Remove and Clear methods to allow be to handle both arrays. On the Add, I would call a base Add on the collection and then call a hash add with my key and the poistion of the object in the ArrayList. The this[] indexer I added with a string (mine was a text value for the key) and did a find using the hash and returned the reference from the base ArrayList by the index pulled from the hash table.
This allowed me to use the foreach on the collection to retrieve them in the order I placed them in the list but still allowed my fast access to an individual value based on the key.
Is simple to build and easy to use!
Rocky Moore <><
|
|
|
|
|
The HashTable is the wrong data container for that kind of functionality, as you've discovered.
In essence, for the HashTable to provide access to its items in constant time--the major advantage to hash tables--it stores them in a kind of hash code order, not in "alphabetic" order (which has a logarithmic access time) or arrival time order (which is linear in time).
Hence when you list the items in a hash table you get them in this bizarre ultra funky order.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Hi All,
I am using GetProcesses API to enumrate all the processes on windows. Using EnableRaisingEvents , I am trapping the Exit event through my delegator.
but Somtimes it works and some times it not. I do not know y it is so..
The code Snippet is as follows:
Process []_WorkStationProcesses= Process.GetProcesses();
for(Index =0; Index < _WorkStationProcesses.Length;Index++)
{
if(_WorkStationProcesses[Index].ProcessName=="Idle")
continue;
_WorkStationProcesses[Index].EnableRaisingEvents=true;
_WorkStationProcesses[Index].Exited+= new EventHandler(new _ProcessExitDelegator(_ProcessExit));
}
then the delegator
public delegate void _ProcessExitDelegator(Object sender, EventArgs e);
void _ProcessExit(Object sender, EventArgs e){
MessageBox.Show(((Process)sender).ProcessName + " Exited");
}
VikramS
|
|
|
|
|
The problem is that your application doesn't have enough rights to access all the processes. Even if this code is run from admin.
For example system procs, when you try to kill them from the task manager some will fail.
|
|
|
|
|
So how i will able to gets those access rights or at least monitor the processes that are not system related.
|
|
|
|
|
I have....
form1.cs and log.cs
on log.cs there is a list box, listBox1 .
now, in log.cs I write to it as follows...
listBox1.Items.Add("HI");
but, now... I want to be on form1.cs and be able to write to listBox1 , which is on log.cs...
How do I do this?
/\ |_ E X E GG
|
|
|
|
|
First, form1.cs needs a reference to log.cs (you probably already have done this):
log objLog = new log();
Next, you need a public or internal accessor for the ListBox in log.cs:
public System.Windows.Forms.ListBox LogListBox<br />
{<br />
get { return this.listBox1; }<br />
}
Now you can add items to the log.cs ListBox from within form1.cs like this:
objLog.LogListBox.Items.Add("Hi");
|
|
|
|
|
haha... no.
how do I refrence to log.cs?
/\ |_ E X E GG
|
|
|
|
|
nevermind... you tell me how to do this 1 line down...
/\ |_ E X E GG
|
|
|
|
|
hmmm, it dosn't work...
do I have to place these any place special in my code... ?
/\ |_ E X E GG
|
|
|
|
|
I have a form with a number of user controls each derived from datagrid. I can't figure out how to tell which user control datagrid has the focus! I tried UserControl.Focused, and it returns false even if I select a cell within the datagrid. I tried overriding the UserControl.Focused property, extending the DataGrid.Focused value, and still no luck.
I'm relatively new to C#, so it's probably something simple related to derived controls.
Help!
|
|
|
|
|
Got it...
ContainsFocus indicates whether the control or any of it's children controls has the focus.
|
|
|
|
|
I have one solution with two projects (project A & project B). Is there a way to "reference" a class in A from within B?
If I'm in project B and from the solution's explorer I choose "Add Existing Item" it copies the file from A's physical directory into B's directory.
I'm sorta trying to forward reference the class.
|
|
|
|
|
Right click on project B, go to Add Reference..., go to the projects tab, select project A and add the reference. That should work.
I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well.
-jhaga on non-native languages
|
|
|
|
|
Thanks, but Project A is not class lib (dll). Its an EXE that contains a class that I need to use in Project B.
|
|
|
|
|
albean wrote:
Thanks, but Project A is not class lib (dll). Its an EXE that contains a class that I need to use in Project B.
You either make it a .dll or include the file as a link. On the "Add Existing Item..." dialog, do you see the small arrow on the "Open" button? Click it and select "Link file". This way, you'll create a link on your project B to the class on the project A. This will have the side effect of including the code of the class on the project B, too, but I think that this is exactly what you're looking for, right?
Acting as a substitute for God, he becomes a dispenser of justice. - Alexandre Dumas
|
|
|
|
|
Why not create a shared dll that resides between them. That's what I usually do if I need to create two apps that share some of the same basic functionality.
I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well.
-jhaga on non-native languages
|
|
|
|
|
Thanks David. That seems to do it.
|
|
|
|
|
Hi, I am collaborating/taking over a project from another developer in my office. One part is a Windows form with a CheckBoxList controls on top and rows of ComboBoxes on bottom like this:
cbo1_1 cbo1_2 cbo1_3 cbo1_4
cbo2_1 cbo2_2 cbo2_3 cbo2_4
etc...
If there is anything selected in the CheckListBox then row 1 is enabled. More rows could be enabled depending on what exactly is checked.
The problem is that so much code is duplicated. For instance, each cbo is bound to a column in a dataset. For each cbo this code exists:
-------------------
private void Populatecbo1(System.Windows.Forms.ComboBox s)<br />
{<br />
s.Items.Clear();<br />
int Count = _aColumn.Length;<br />
for(int i =0; i < Count; i++)<br />
{<br />
s.Items.Add(_aColumn[i].ToString());<br />
}<br />
} ---------------------
and one for cbo2 and so on. Theres also literally thousands of lines of switch statements for enabling/disabling cbo's.
Isn't there a better way to do this without duplicating all of this code?
Thanks,
Robert
|
|
|
|
|
RblEdwards wrote:
Isn't there a better way to do this without duplicating all of this code?
Without seeing the full code it's not going to be possible to supply a working example, but the answer to your question given the information here is a resounding YES.
I would suggest creating an array of ComboBox controls, and iterating over them to populate them and set the Enabled property, there's a good chance you will be able to reduce it down to 3 or so methods.
e.g.
int cols = 10;
int rows = 10;
System.Windows.Forms.ComboBox[,] comboArray;
comboArray = new System.Windows.Forms.ComboBox[cols, rows];
Another possible option would be using a DataGrid to display the data and combo boxes (there's plenty of examples online for putting ComboBoxes in DataGrid cells), and simply manipulating the DataGrid properties to enable/disable item editing.
|
|
|
|
|
In addition to Furty's response...
If you have a collection of controls you can either populate them at
design-time (which leads to code like you've got) or you can programmatically add them yourself.
Try this:
Create a new project and put a GroupBox on the form
Add a single control to that GroupBox
Look at the Windows Generated code.
Now you have a template for what YOU would do, since the logic is adding a single control to the Control collection. Rip out the Windows generated code and make it a programmatic loop to add each control. Now --- if you have an event like having an item selected, point it to a single routine in your build code. If it is necessary to know which control from top to bottom was selected, you can interate through the Control collection until you find that control, and that becomes the index for populating the corresponding control in the other groupbox.
The beauty of reusability!
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
I have Thread.Sleep in my program, and to fastest I can get it to sleep is 1 milla second...
I need it to be faster...
1 Micro second....
and way to do this?
/\ |_ E X E GG
|
|
|
|