|
hi everybody
anybody knows how can i save drop down box items in a text file?
thank you
|
|
|
|
|
Try something like this:
using (System.IO.StreamWriter sw = new System.IO.StreamWriter("test.txt",false))
{
foreach(object o in this.comboBox1.Items)
{
sw.WriteLine(o.ToString());
}
sw.Close();
}
/cadi
24 hours is not enough
|
|
|
|
|
The sw.Close call is redundant, the "using" statement automatically closes the StreamWriter when control reaches the end of the block.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Yup, I know this is true for the StreamWriter (and should be for any class implementing the IDisposable interface).
I just can't get rid of the habit to be on the safe side.
And sometimes i have something like this:
using (x)
{
using(x.y)
{
x.Close();
}
}
by calling the x.Close i simply free the resource as soon as i do no longer need it, not as soon as the finally of the using statement is reached.
And finally you never know if the IDisposable.Dispose actually does implement all the stuff you expect it to contain.
OK, your are right... it is redundant (but i still have my points!)
/cadi
24 hours is not enough
|
|
|
|
|
Hmm. Just for the sake of argument,
using (x)
{
using(x.y)
{
x.Close();
}
}
After all, that's the sole purpose of the using statement
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
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
|
|
|
|