|
If you want to only have a list of possible items, then you should use a List.
Instead, if you want to have each item in a list to have some sort of reference number, a key, you should use a Dictionary.
The dictionary is located at System.Collections.Generic;
To make a Dictionary and use the basic functionality, see the following example:
<br />
public void myMethod()<br />
{<br />
Dictionary<int, string=""> dict = new Dictionary<int, string="">();<br />
dict.Add(1, "item1");<br />
dict.Add(2, "item2");<br />
<br />
dict.ContainsKey(1);
dict.ContainsKey(5);
dict.ContainsValue("item1");
dict.ContainsValue("item5");
<br />
string value = dict[1];
string value = dict[2];
}<br />
</int,></int,>
Here it will add 2 values with each an own key. "item1" with the key 1, "item2" with the key 2. So if you for instance want to find the value that belongs to the key 1 (in your example Task.CompareID), you do string value = dict.[Taks.ComprareID] .
Note here that you can use everything for the key and value, not only int and string. You are able to use objects. For objects it goes exact the same as with the int and string to find them: they have to be an exact match.
|
|
|
|
|
Your current code isn't using generics. If it was, then it would be more like
List<task> tasks = new List<task>();
</task></task>
For the compare code, look into how the List takes a custom IComparable object at creation time. I think it is just on the constructor. So you would create a class for your compare logic that implementes IComparable. Then pass that into the constructor for you list. Example:
public class TaskComparer: IComparable
{
public int Compare(Task x, Task y){}
}
...
List<task> tasks = new List<task>( TaskComparer );
</task></task>
If that doesn't work, then you need to create your own type of List that inherets from the base List<> class, override the Find and implement your own code.
|
|
|
|
|
I am working with Visual Studio 2008, .NET Framework 3.5 and C#.
I have my own Console Application that needs some functionality. Currently it is able to change the Windowtitles, read it's location on the screen, read it's width and height, send mouse-events and send key-events. This can be done to any open window, as long as I have the handle for it (which normally never is the problem).
The only thing I am missing is how to capture the messages that are send to this handle. With Spy++ I am able to see all the messages send to a window, I want the same functionality in my Console Application.
A simple example of such message will be: WM_MOUSEMOVE fwKeys:0000 xPos:10 yPos10
To make everything clear what I exactly want:
My Console Application has to read all messages send to a handle that is not created by the Console Application, for instance a window like Internet Explorer or Notepad. Those messages have to be captured.
So far I have tried both GetMessage and PeekMessage. The code I used for that is as follows
<br />
[DllImport("User32.dll", CharSet = CharSet.Auto)]<br />
private static extern bool PeekMessage(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);<br />
<br />
[DllImport("User32.dll", CharSet = CharSet.Auto)]<br />
private static extern bool GetMessage(out MSG msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax);<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct MSG<br />
{<br />
public IntPtr hWnd;<br />
public uint Message;<br />
public uint WParam;<br />
public uint LParam;<br />
public uint Time;<br />
public System.Drawing.Point Point;<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
System.Threading.Thread.Sleep(2000);<br />
<br />
MSG msg;<br />
while (PeekMessage(out msg, new IntPtr(0x000A053A), 0, 0, 0))<br />
{<br />
System.Threading.Thread.Sleep(2000);<br />
}<br />
<br />
while (GetMessage(out msg, new IntPtr(0x000A053A), 0, 0, 0))<br />
{<br />
System.Threading.Thread.Sleep(2000);<br />
}<br />
}<br />
For me, this always results a false value for both the PeekMessage and GetMessage methods and thus no value in msg. Does anybody know how to solve my problem?
Thank you very much in advance!
|
|
|
|
|
Check this[^] out.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Sorry for the late response, but I have been working on it.
What you send is not realy what I need, that is basically built to read messages of .NET components. What I need is to read messages of any program that is running.
Through my long research I discovered Windows does not realy allow this on an easy and efficient way. You have to inject your DLL into the program in order to make it work right.
This is too much work for me...
But for me, the problem was something else, it was Visual Studio 2008.
There is a setting called "Enable the Visual Studio hosting process". This must be turned of in order to make this work. This setting can be found at:
Project >> [project name] Properties... >> Debug >> Enable Debuggers
Thank you for your information, but now I'm just working with Low Level hooks and reading from what program the message comes.
|
|
|
|
|
|
Jamie1985 wrote: CREATE PROCEDURE create_temp_itemschedule AS
CREATE TABLE temp_itemschedules (
Item_Schedule_ID int,
Item_Ref nvarchar (10),
room_code nvarchar (14),
instance_variant int,
ignore_flag nvarchar (1),
Qty_New int,
ADB19_2_Qty int,
Qty_Trans int,
Revision_Version nvarchar (50),
Revision_By nvarchar (50),
Revision_Date smalldate (4),
Revision_Source Ntext,
Notes Ntext)
GO
Jamie - the way to test something like this is to take the statements out and attempt them by yourself in SQL Server. If you had done this, you would have found the reason in a matter of seconds, namely that there is no smalldate datatype in SQL Server (and you need to remove the size of the same field as well - if it's a date it doesn't need a size specifying).
|
|
|
|
|
Don't delete posts when someone replies.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
hi all
i have two forms FORM1 and FORM2.and form1 has two buttons.
when buttons B1,B2 is clicked in FORM1, FORM2 should appear,
but i need to trace which button is clicked .so that i want to display dfferent controls in FORM2 accordin to button click.
Any body give some tips
I am trying to trace the "event e" in the FORM2 's load event.
pls help
senthil
|
|
|
|
|
You can either have two event handlers for your two buttons to distinguish which one was pressed or you can examine the sender property by casting it to appropriate type
|
|
|
|
|
if the event handler is same then use this:
Button b = (Button)sender;
now you can indentify the button by "Name", "Text" or any other property
Becoming Programmer...
|
|
|
|
|
I want to create nullable combobox whuch stores null to datasource when Text
is empty and null value is not in ComboBox Item list.
I tried the code below but null is not stored to s.CustId.
How to change this code so that null is stored to s.CustId ?
It it possible to store null without adding null entity to Customer class ?
I have generic ComboBox which allows to select foreign keys from Customer,
Product etc.
lists.
Generic code to instantiate and add null Id to every such objects seems to
be compilated.
In every list Id and Name propetries have different names, eq. names may be
productname, customername, productcode, customervatno etc.
So I must use CreateInstance to create empty entity object and then use
reflection to set id property to null and foreign key property to empty
string.
This seems to be complicated. So I'm looking for a simpler way to allow
Combobox natively support this.
Andrus.
using System.Windows.Forms;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
<br />
class testForm : Form {<br />
<br />
Storage s = new Storage();<br />
<br />
testForm() {<br />
<br />
Customer c = new Customer();<br />
c.Id = "J";<br />
c.Name = "John";<br />
List<Customer> l = new List<Customer>();<br />
l.Add(c);<br />
<br />
NullableComBobox cm = new NullableComBobox();<br />
cm.DisplayMember = "Name";<br />
cm.ValueMember = "Id";<br />
cm.DataSource = l;<br />
<br />
s.CustId = "J";<br />
cm.DataBindings.Add("SelectedValue", s, "CustId");<br />
<br />
Controls.Add(cm);<br />
Button b = new Button();<br />
b.Top = 80;<br />
b.Click += new System.EventHandler(b_Click);<br />
Controls.Add(b);<br />
}<br />
<br />
void b_Click(object sender, System.EventArgs e) {<br />
<br />
if (s.CustId == null)<br />
MessageBox.Show("Value is null");<br />
else<br />
MessageBox.Show("Value is NOT null "+s.CustId.ToString());<br />
}<br />
<br />
class Customer {<br />
public string Id { get; set; }<br />
public string Name { get; set; }<br />
}<br />
<br />
class Storage {<br />
public string CustId { get; set; }<br />
}<br />
<br />
static void Main() {<br />
Application.Run(new testForm());<br />
}<br />
}<br />
<br />
public class NullableComBobox : ComboBox {<br />
<br />
protected override void OnValidating(CancelEventArgs e) {<br />
<br />
if (Text.Trim().Length == 0) {<br />
SelectedIndex = -1;<br />
base.OnValidating(e);<br />
return;<br />
}<br />
<br />
int pos = FindString(Text.Trim());<br />
<br />
if (pos >= 0) {<br />
SelectedIndex = pos;<br />
base.OnValidating(e);<br />
return;<br />
}<br />
<br />
e.Cancel = true;<br />
MessageBox.Show("Invalid entry");<br />
base.OnValidating(e);<br />
}<br />
}
Andrus
|
|
|
|
|
hi
I am using Textbox contrl which is disabled for some conditions.
I would like to make the Textboxes back color as white as it looks when it is enabled? Can u pls help how to change its back color?
Thank u
senthil
|
|
|
|
|
Please don't repost a question just to push it back to the top of the forums. This isn't good.
|
|
|
|
|
sorry i actually never meant to repost to make it visible at top!
it was my net problem. since when processing slowed i pressed the post button twice.
kssk
senthil
|
|
|
|
|
kssknov wrote: it was my net problem. since when processing slowed i pressed the post button twice.
Hey, it happens
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Probably the easiest way to do this is for you to derive your own control from the textbox and handle the different background colour in there.
|
|
|
|
|
Not sure if this is an option for your particular situation or not.
When I need behavior like this I set the textbox to readonly instead of disabled. That way I can modify the backcolor.
txtBox.ReadOnly = true;
txtBox.BackColor = System.Drawing.Color.White;
Hope this helps.
|
|
|
|
|
man, it quite easy, just change backcolor to White from Windows
Becoming Programmer...
|
|
|
|
|
I thought you could set a textbox to ReadOnly and Enabled .
ReadOnly would leave the BackColor to white, while Enabled would set it gray.
you can always set the BackColor to virtually any Color you want after you've set it ReadOnly or Enabled
Hope this helps.
|
|
|
|
|
IIRC read only allows you to select text, disabled does not.
Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop.
-- Matthew Faithfull
|
|
|
|
|
HI
Can any one kindly let me know, how the array list has been implmented in .Net frame work, i have heard it has been implemented as link list at the back end, kindly let me know asap, thankx in advance,
regards,
|
|
|
|
|
You can use Reflector for .NET to see how it is implemented or wait until the source code is released publicly by Microsoft.
|
|
|
|
|
Hi,
I have a MIB file, here's a piece:
nlmLogVariableOpaqueVal OBJECT-TYPE<br />
SYNTAX Opaque<br />
MAX-ACCESS read-only<br />
STATUS current<br />
DESCRIPTION<br />
"The value when nlmLogVariableType is 'opaque'."<br />
::= { nlmLogVariableEntry 12 }<br />
<br />
<br />
--<br />
-- Conformance<br />
--<br />
<br />
notificationLogMIBConformance OBJECT IDENTIFIER ::=<br />
{ notificationLogMIB 3 }<br />
notificationLogMIBCompliances OBJECT IDENTIFIER ::=<br />
{ notificationLogMIBConformance 1 }<br />
notificationLogMIBGroups OBJECT IDENTIFIER ::=<br />
{ notificationLogMIBConformance 2 }<br />
<br />
-- Compliance
How can I get every occurence of OBJECT IDENTIFIER? I do something like this:
Regex objIdentifiers = new Regex(@"(?<name>[a-z][\d\w0-9-]*).*(\n|\s|\t)*OBJECT IDENTIFIER.*(\s|\t|\n)*::=(\s|\t)*{(\s|\t)*(?<enterprise>[\d\w0-9-]*)(\s|\t)*(?<number>[0-9])(\s|\t)*}");<br />
<br />
MatchCollection matches = objIdentifiers.Matches(s);</number></enterprise></name>
But this doesn't work. I should mention that those definitions sometimes look like this:
notificationLogMIBGroups OBJECT IDENTIFIER ::=<br />
-- Comment<br />
{ notificationLogMIBConformance 2 }
Thanks in advance!
Greetings.
ps. after quotation marks are group names, but I don't know why won't show them in this post :/
|
|
|
|
|
hi i want to i have 100 user name in a data table and want to show them in multiple coulmn in Crystal report means that fir 25 in firsy column then 25 to 50 in second columns and the 50 to 75 in thrid Column and remaining in fourt coulmn how i can do this
wasim khan
|
|
|
|