|
KPThor wrote: Is something like this possible where the value of a variable is used instead of MenuBarEdit?
I don't see what you are trying to achieve?
KPThor wrote: string mbitem = MenuBarEdit;
this.mbitem = new System.Windows.Forms.MenuItem();
The second line is (EDIT: Actually both lines are) invalid because you cannot assign a MenuItem to a string .
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
I am trying to use the text value of a string so the menubar could be dynamically modified from a xml file when the program loads.
<?xml version="1.0" encoding="utf-8"?>
<Menu>
<MenuBar item="File">
<MenuItem item="Open" acion="call" />
<MenuItem item="New" action="sub">
<SubMenuItem item="File" acton="call" />
<SubMenuItem item="Folder" action="call" />
</MenuItem>
</MenuBar>
<MenuBar item="Edit">
<MenuItem item="Cut" action="call" />
<MenuItem item="Copy" action="call" />
<MenuItem item="Paste" action="call" />
</MenuBar>
</Menu>
When the parser reads the xml file and comes to <MenuBar item="File"> and <MenuBar item="Edit"> it can place those menu items in the menubar.
|
|
|
|
|
KPThor wrote: When the parser reads the xml file and comes to <menubar item="File"> and <menubar item="Edit"> it can place those menu items in the menubar.
Okay - but all you need to do for that is add the item to the Controls collection of the control that will be the parent (e.g. A form, or a MenuStrip). You don't have to store it anywhere else (unless you want to)
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
I use this code to read some records from a access database with contacts exported from Outlook.
I get an error when the content of a field in the db is NULL bc it cannot be converted to string.
How could I correct this and the convert a Null field in a " " string?
Thanks
static void Main()
{
Program instan = new Program();
instan.ReadContacts();
Console.Read();
}
public void ReadContacts()
{
try
{
OleDbDataReader reader = null;
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\AGH\\epafes_outlook_2007.accdb;Persist Security Info=False");
string comStr = "SELECT FirstName, LastName, BusinessPhone FROM Contacts";
OleDbCommand cmd = new OleDbCommand(comStr, conn);
conn.Open();
reader = cmd.ExecuteReader();
int i=1;
while (reader.Read())
{
string FName = (string)reader["FirstName"];
string LName = (string)reader["LastName"];
string BPhone = (string)reader["BusinessPhone"];
Console.Write("{0,-4}", i);
Console.Write("{0,-13}", FName);
Console.Write("{0,-13}", LName);
Console.Write("{0}", BPhone);
Console.WriteLine();
i++;
}
Console.WriteLine("\nFinish");
conn.Close();
reader.Close();
}
catch (Exception e)
{
Console.Write(e);
}
}
|
|
|
|
|
string FName = string.Empty;
object temp = reader["FirstName"];
if (temp != DBNull.Value)
FName = (string)temp;
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
kallileo wrote: string FName = (string)reader["FirstName"];
string LName = (string)reader["LastName"];
string BPhone = (string)reader["BusinessPhone"];
If a column is nullable in the DB, you should check for nullity in your code. Unfortunately, it is not the same as .NET null . You have to do it this way:
<code>
if (reader.IsDBNull(reader.GetOrdinal("FirstName"))
{
FName = null;
}
else
{
FName = (string)reader["LastName"];
}<code>
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
Le Centriste wrote: You have to
"have to" is a bit strong. You don't "have to" do it that way (although it is a reasonable way to check) as there are other reasonable alternatives.
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
Yes, you're right. Wrong choice of words. I should have said "Here is an example".
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
I think I found it....and it seems to work. But I'm not realy sure if this is the right way to do it.
string FName = Convert.ToString(reader["FirstName"]);
string LName = Convert.ToString(reader["LastName"]);
string BPhone = Convert.ToString(reader["BusinessPhone"]);
Thanks
-- modified at 9:17 Friday 20th July, 2007
This also works:
string BPhone = reader["BusinessPhone"].ToString();
|
|
|
|
|
Curiously, if you look at what Convert.ToString actually does, it just boils down to the same as:
string FName = reader["FirstName"].ToString();
So, is DBNull.Value.ToString() the value that you really want back?
Upcoming events:
* Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ...
"I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless."
My website
|
|
|
|
|
DBNull.Value.ToString() returns an empty string, so it boils down to be the same as the examples we give, I believe.
-----
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
|
|
|
|
|
Hi
Since string is a reference type you could also do it like this:
<br />
string FName = reader["FirstName"] as string;<br />
string LName = reader["LastName"] as string;<br />
string BPhone = reader["BusinessPhone"] as string;<br />
greets
M@u
|
|
|
|
|
m@u wrote: Hi
Since string is a reference type you could also do it like this:
string FName = reader["FirstName"] as string;
string LName = reader["LastName"] as string;
string BPhone = reader["BusinessPhone"] as string;
greets
M@u
Thanks....
Colin Angus Mackay wrote: Curiously, if you look at what Convert.ToString actually does, it just boils down to the same as:
string FName = reader["FirstName"].ToString();
So, is DBNull.Value.ToString() the value that you really want back?
Yes, it is ok to me...
|
|
|
|
|
I have a text box, this is to be completed by the user. It has multiline and wrap=true properties.
The user completes the web page with data and then can have the option of a printer friendly version of the completed page. My printer friendly page has a label and the data from the text box is returned in to the label.
Of course this is now not wrap round and the control characters etc are in the print instead of formatting the text.
I changed the label to a read-only text box but this does not show all the text available for printing. This should be easy but I can't think it through. Any help welcome
|
|
|
|
|
Hi,
Could you please further explain it?
Do you mean it in ASP.net?
Nisha S.
|
|
|
|
|
|
Hi all,
Well i am trying to get message over textbox which is in a loop and contains many messages. But then the problem was that my form was not responding if i switch to any other application n return back to it. So it use to hang. So some1 told me to use BackGroundWorker Class. And i did that and the below code is working absolutely fine...just hv a look below..
<br />
namespace BackgroundThread<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
private BackgroundWorker worker = null;<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
worker = new BackgroundWorker();<br />
worker.DoWork += new DoWorkEventHandler(worker_DoWork);<br />
worker.RunWorkerAsync();<br />
<br />
}<br />
<br />
void worker_DoWork(object sender, DoWorkEventArgs e)<br />
{<br />
for (int i = 0; i < 100000; i++)<br />
{<br />
if (InvokeRequired)<br />
Invoke(new Change(OnChange), i);<br />
}<br />
<br />
private void OnChange(int i)<br />
{<br />
textBox1.Text += i.ToString() + ",";<br />
Application.DoEvents();<br />
Thread.Sleep(100);<br />
}<br />
<br />
private delegate void Change(int i);<br />
<br />
}<br />
}<br />
<br />
Now comes the problem part. Suppose now i have a button over form and after clicking that it should write messages over the text box after the aboce code finish executing. But i dont know how to include that in a thread...just have a look below...
<br />
<br />
private void startBtn_Click(Object sender, EventArgs e)<br />
{<br />
int Count = 0;<br />
while(true)<br />
{<br />
if(count > 1000)<br />
{<br />
break;<br />
}<br />
<br />
Thread.Sleep(1000);<br />
textBox1.Text += "Message" + Environment.NewLine;<br />
textBox1.Refresh();<br />
count++;<br />
<br />
}<br />
<br />
The above code again makes the form not responding after i press the start button. <br />
Well i know its a threading problem and i dont have much experience in threading. <br />
<br />
Well actually the above code is just an example. My real application is different and would give message over text box from different parts of application. So how to solve this case..if there is any easy way out like to refresh the form every time...etc...<br />
<br />
Any help would be greatly appreiated..<br />
Thanks<br />
<br />
<br />
|
|
|
|
|
Software_Specialist wrote: The above code again makes the form not responding after i press the start button.
Thats probably because the while loop at the beginning of the start button click event will be infinite (assuming Count and count are the same variable, you just typed differently)
But a couple of points in your code.. If you are using BackGroundWorker you should not do Application.DoEvents. That can cause problems. Also you are doing a Thread.Sleep in OnChange, which is being called from the GUI thread. So I guess this will hold up your GUI thread?
So basically, no DoEvents and no sleeping on the GUI thread should make it better.
|
|
|
|
|
Actually your app is probably not responding because you're calling Thread.Sleep(1000) for 1000 times from the main thread your application is running on. After a thousand seconds it'll be responsive again. You should run your code from a separate thread.
Again, you should use a background worker for your loop and update your controls using the report progress mechanism of the background worker or something similar. I showed you the code for this some days ago I think here
Standards are great! Everybody should have one!
|
|
|
|
|
Hi body...
I have a datagrid with a binding source. when I try to go out of that row there are a multitude of events that get raised (dataError, cellvalidating, rowvalidating, ...) does somebody know the exact sequence of those events?
for exemple, at the moment I know that when I change the selected row first I have a RowValidating, then a rowValidated and finally a SelectionChanged. Are all those sequences written somewhere?
Thank you very much
Life is not short... the problem is only how you organize yourself
|
|
|
|
|
JoZ CaVaLLo wrote: does somebody know the exact sequence of those events?
Well if you create handlers for each one then add Debug.WriteLine statements in them and launch a Debug instance and look at the results in the Output window, then you will know what the sequence is. I hope this is a school project.
|
|
|
|
|
Hi all,
I've implemented drag 'n drop for internal and external drag operations. However, I need to test for which mouse button is currently being pressed to enable different functionality.
The MSDN documentation for DragEventArgs suggest using the KeyState property and testing it's value to do this.
Now here comes the wierd part: I had this working a little while back. Nothing has changed in that section of code.
And the KeyState property has a value of 0 (which is impossible because that would mean no buttons at all are being pressed, so why is there a drag operation occurring?).
Anyone had any experience with this situation and/or know what the problem is and how to fix it?
|
|
|
|
|
Hi,
This is my first message to this forum. I beleive you guys are very helpful. Pls reply me on the following.
I have two forms one contain grid to list all the data and a add button. When I press the add button it opens a new form to insert record. Then I press save it saves to the database and close. But I need to reload the first form with the added record before closing the second. I have tried hard to find the answer. Pls help me on.
Thank you.
Nisha S.
|
|
|
|
|
Nisha S. wrote: This is my first message to this forum
Wellcome!
Nisha S. wrote: I need to reload the first form with the added record before closing the second
I would use the ShowDialog() method to show the second form modal.
This will allow you to reload the datas in the mainform, when the method finished (second Form closes)
If you have to use Show(), you would need to handle the Closeing or Closed event of the second form.
Hope it helps!
All the best,
Martin
|
|
|
|
|
Simple method. But I don't know how much efficient is this when considering about big applications. What you can do is pass first forms object to second form when second from loads. Make datagrid to public. Using first forms object you can access datagrid. Bind that as you do always
|
|
|
|