|
hihi... you win...
/cadi
24 hours is not enough
|
|
|
|
|
hi
can anybody help me to see if a certain item exists in a drop down box?
thank you
|
|
|
|
|
Use the Contains function on the drop down box's Items property. Like
...
bool isItemPresent = comboBox.Items.Contains(itemToBeFound);
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thanks
but this code returns an error:
if (drpSelected.Items.Contains(lblID.Text) == false)
how can i convert my label text to an item?
|
|
|
|
|
Farhad Eftekhari wrote:
but this code returns an error:
Which one? It would be easier to help if you said what exactly that error says. (with stack trace if possible!)
Farhad Eftekhari wrote:
how can i convert my label text to an item?
You don't. If your drpSelected.Items contains array of string , than it works. If it does not, item text (displayed in control) are result of item's ToString() method. Now think about it. What Contains method need to find your item? It must be able to say if some item from items is (equals) to item you are searching for. So, in order to make THIS example work, you can a) have only strings in drpSelected.Items (so Contains will compare string references) or b) override Equals() method for items or c) if( drpSelected.Items.Contains( item ) ) . First option seems to be best, but then again we have no idea what your code *really* means.
[edit]
or you can create new item (e.g if( drpSelected.Items.Contains( new item(lblID.Text) ) ) )+ override Equals() . But that sounds quite stupid
hmmm it looks like your drop has something to do with IDs? I suspect your Item have properties Item.UserName and Item.ID , right? Don't you need only selected one? Than use SelectedValue instead of SelectedText . (you must fors say what is Value "column" -ListControl.DataValueField Property[^] )
[/edit]
Does it help?
David
|
|
|
|
|
Where can i find a good article about c# and exchange server. I need to programmically delete email in a particular mailbox and other possible functions.
Please help
|
|
|
|
|
|
Ohh ... i just review your link and i don't think that would be my purpose. My application will send a email into serveral mailboxs and if those users click a submit button on that emails and successfully postback to the server page, these emails has to be automatically removed (controled by my script) from their mailboxs .
I know there are so many DLLs and implementation i can use, such as WebDEV, CDO, or etc, but i need a good starting point ...
Thannk you
|
|
|
|
|
http://www.cdolive.com[^] is a good resource for everything about client and server side CDO.
_________________________________
Please inform me about my English mistakes, I still try to learn your language!
|
|
|
|
|
Hello All,
I select a Data from my databae and saved in the dataset i need to insert in this dataset new row at spacific position with the method InsertAt()
myDataSet.Tables[0].Rows.InsertAt()
Please help with example
Regards,
Hay
|
|
|
|
|
i need to call that function inside my c# application, how can i?
|
|
|
|
|
In the System.Windows.Forms.UnsaveNativeMethods class (which is marked as internal) it is defined as:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
If you define it just like this you can use it in your own code.
/cadi
24 hours is not enough
|
|
|
|
|
why if i add this row:
[DllImport("user32.dll", CharSet=CharSet.Auto)]
i get a compile error.
What do i have to specified to the compiler?
|
|
|
|
|
You probably get a "DllImport" not found (or the like) message.
Simply add this line to you file:
uses System.Runtime.InteropServices
/cadi
24 hours is not enough
|
|
|
|
|
cadi wrote:
uses System.Runtime.InteropServices
I smell Pascal :P
David
|
|
|
|
|
er... actually it should be using
It is somwhat differnt from the uses clause in pascal.
Using is simply telling the compiler to try to prefix the namespace for any non local symbol.
The Pascal uses equivalent in C# is the References section in your solution.
Btw. my I ask why you need a call to the DefWndProc in C#?
What kind of subclassing strategy are you up to? I have not yet entered any scenario where i would like to call the DefWndProc directly since it is completely encapsulated by the framework.
/cadi
24 hours is not enough
|
|
|
|
|
cadi wrote:
The Pascal uses equivalent in C# is the References section in your solution.
yes.
cadi wrote:
Btw. my I ask why you need a call to the DefWndProc in C#?
You are asking wrong person...
David
|
|
|
|
|
|
May I ask why you need a call to the DefWndProc in C#?
What kind of subclassing strategy are you up to? I have not yet entered any scenario where i would like to call the DefWndProc directly since it is completely encapsulated by the framework.
/cadi
24 hours is not enough
|
|
|
|
|
of course, i'm overring some windows message to avoid to draw the form title bar as unactive.
It is just a hard stuff
|
|
|
|
|
Shouldn't something like this do the magic?
<code>
protected override void WndProc(ref Message m)
{
const int WM_NCPAINT = 0x0085;
if (m.Msg == WM_NCPAINT)
{
m.Result=(IntPtr) 0;
return;
}
base.WndProc (ref m);
}
the base.WndProc(ref m) calls the DefWndProc then...
/cadi
24 hours is not enough
|
|
|
|
|
i've tried and it just doesn't draw correctly the form
|
|
|
|
|
Hello,
I need to mimic, in code at run time, the behavior that takes place when ListView.AllowColumnReorder is true and the user drags/drops columns to reorder them.
To be more specific, I want to be able to edit a subitem in place (which C# doesn't allow). Someone on CodeProject wrote a ListViewEx that does this but that's overkill.
I have a simple listview with 2 columns: Name and Weight (a numeric value). I don't want Name to be editable, but I want it appearing first. I want Weight to be editable but have it appear second. I know that if I put the Weight column as the first column and then reorder columns using drag/drop, I can still edit the Weight column's data even after reordering the columns . I want to "cheat" and create the listview, then mimic the column reordering in code so that the Weight column appears second but remains editable.
|
|
|
|
|
Hey!
Intruduction:
I am using Framework 2.0(beta 2) and the System.IO.Ports.SerialPort class to communicat with serialport/USB devices.
I have built my serialport communication with Events, like this:
<br />
#region Create Connection<br />
serialPort = new SerialPort(serialPortSettings.getPort, serialPortSettings.getBoudRate, serialPortSettings.getParity, serialPortSettings.getDataBits, serialPortSettings.getStopBit);<br />
serialPort.DtrEnable = true;<br />
serialPort.RtsEnable = true;<br />
serialPort.ReceivedBytesThreshold = 4;<br />
serialPort.Open();<br />
#endregion<br />
<br />
serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_ReceivedEvent);<br />
SerialPort Settings that I use
Baud rate: 115200
Data bits: 8
Parity: None
Stop bit(s): 1
This is done by a special serialport thred, this to make sure that the main thread(the one that redraws the GUI and so on) not will be involved in the event firing of this serialport.
In serialPort_ReceivedEvent you can finde the folowing code:
<br />
lock (this)<br />
{<br />
if (RUNNING)<br />
{<br />
ThreadPool.QueueUserWorkItem(new WaitCallback(onDataReceived));<br />
currentRunningThreads++;
}<br />
}<br />
This function will be fired as soon as 4 bytes(ReceivedBytesThreshold) have been written to the serialport. As you can see, it will place a work in the ThreadPool and then make the current thread available for next event.
The onDataReceived looks like this.
<br />
if (RUNNING)<br />
{<br />
lock (this)<br />
{<br />
if (serialPort.BytesToRead > 0)<br />
{<br />
string data = serialPort.ReadExisting();<br />
<br />
<br />
if (data != null && data.Length > 0)<br />
{<br />
RemovePortHandlerRAW.Write(data);
RemovePortHandlerRAW.Flush();<br />
<br />
data = toolHandler.costmizeString(data, timeStamp, showCR_LFOnIncomingData);<br />
<br />
streamHandler.writeData(data);
<br />
if(SAVEDATATOFILE)<br />
rows = toolHandler.stringToArray(data);<br />
<br />
if (rows != null)<br />
{<br />
if (SAVEDATATOFILE)<br />
dataCollector.writeArrayToFile(rows);<br />
}<br />
}<br />
}<br />
}<br />
As you can see, am doing different things in this onDataReceived function, but the main part is: ReadExisting on the serialport and writes it to file to be abled to compare it with the file I am realy sending to my program by using CompareIt(http://www.grigsoft.com/)
TEST:
I have created a program that sends a 2 MB file with a serten data structure where every row ends with CRLF. This program sends one char at a time and this as fast as posible over a nullmodem cable (from laptop to my computer)
When the file is transfared to my computer from the laptop, it will be compared with the file I sent from my laptop, to ensure that no data is lost.
Test Result:
I have manage to find a good ReceivedBytesThreshold(decides how many byte that have to be written to the serialport before the event is fired) on the serialport that I don’t lose any data, but have a good CPU usage. I first tried 512, 256, 32. But all this value will result in some Dataloses in high speed. I then tested 4, and that works good(no data loses).
Why not choose 1? By choosing 1 in ReceivedBytesThreshold will result in a higher CPU usage.
Stress Test:
To ensure that no data will be lost I hade to made some stress tests.
Test 1:
I tried to move around a firefow window(web browser) with an andvance page loaded(like www.gamespot.com). By doing this I get 100% CPU usage, and if I do this as long as posible during my program is receiving data over the nullmodem cabel, this test showed that data are lost during stress test like this!!
Sometimes it could also result in an array that says that a Thread have been interupted, but I don’t realy know why?
Test 2:
By open a window in WindowsXp with some files in and the hold F5 pressed it will update the window so fast that the CPU usage will be 100%. But this will strangly not effect the data flow? No data is lost?
Problems:
As you can see, I cant get a sequre data transfer! I have tried other program with the same stress tests like the one here http://www.aggsoft.com/, but this works fine!
Maby this is I Microsoft problem, maby the serilaport in framework 2.0 is not reay finished yet?
Maby I shouldt buther with the outcome on Test1?
I have also tried to have a Thread loop instead of the events, but that dident help(same problem).
I realy need help here, It would be great if anyone else have the posibility to try the exact same thing.
Best Regards
SnowJim
|
|
|
|
|
The problem is with you using ThreadPool threads to write to the file. I'm pretty sure you expect the contents of the file to be in the same order as you sent. But using threads to write to the file will surely result in data misordering.
When you call ThreadPool.QueueUserWorkItem , the system assigns a thread to run the function. There is no guarantee that the function would complete before you get another serialPort_Received event. Imagine the case when the first thread has read the contents but before it writes to the file, there is another serialPort_Received event and that thread writes to the file first. Your file wouldn't have the contents in the right order then.
I suspect that's why you're getting strange results when the CPU is busy. When the CPU is relatively idle, it probably schedules your threads in such a way that each DataReceived event occurs after the ThreadPool thread has completed.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|