|
Fairly easy indeed. This eliminated the API calls required to check if the form exists (which was pretty sloppy I must say).
Everything works great now. I declared formA/B as private. Then created public methods CloseA/CloseB, which dispose/close the form and set the priv variable to null.
(The class is not static btw, I do initiate it in my main app)
Then created a method in the class library form which Invalides/Updates the picture box with the new value.
I can't believe I spent 5 hours googling/messing around on something that took 5 seconds to fix lol.
|
|
|
|
|
Glad that you got it working. I misunderstood your reply to Josh above, so I thought you needed static methods and variables. As long as you're creating instances of Class2, things are pretty straightforward
Sincerely,
Alexander Wiseman
|
|
|
|
|
Yep. I ran into a small road block, but I think I'll be able to fix it (in under 5 hours heh).
If I close the Class 1 form with the [X], I can't re-open it because the Class 2 private variables aren't set to null. Trying to figure it out, without having to set those variables as public.
|
|
|
|
|
When you close a form with the [X], two events occur: first Closing and second Closed . Simply add an event handler inside Class2 for one of these events (probably the second one would be better) and set the variable to null there, or whatever else needs resetting.
Here is some sample code:
public void ShowA(string displayValue)
{
if(formA == null)
{
formA = new MainForm();
...
formA.Closed += new EventHandler(formA_Closed);
... formA_Closed refers to a function inside Class2 which must have the following signature (i.e. parameters):
public void formA_Closed(object sender, EventArgs e) Inside that function, reset whatever you need to.
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Ah. That worked. Took a bit of tinkering though.
Users have 2 ways of closing the form. 1 is with the [X] and the other is automatic, when they leave a textbox (the windows pop up when they enter a textbox).
Original close code ->
public void CloseA()
{
formA.Dispose();
formA.Close();
formA = null;
}
This worked, until they closed with the [X] (discussed above).
I added your event handler code, which just set the private formA variable back to null, nothing else.
Problem with that was, when they left a textbox, it was running the close function and trying to dispose/close the form, but the event handler must have triggered first (I wasn't sure how to call the event handler directly from outside the class , formA_Closed(null, null) didn't seem to work).
Long story short, I checked if (formA != null), then dispose/close in the original CloseA() function. All is merry now.
Thanks again.
|
|
|
|
|
I have several C++ server programs that were written to be accessed via RPC from C++ client programs, with interfaces defined in IDL files. Now, I want a client program to be in C# and to use the same interface.
I found on the web some information about running midl to produce a tlb file and then running tlbimp to produce an assembly in a dll that I could presumably import into my C# program. But I'm stuck at square one. My IDL files never delcared a library XXX { ... }. They only declared an interface. Without a library declaration, no tlb output file gets produced. But if I blindly put "library XXX {" before the interface declaration in the IDL file and "}" at the end of it, midl then gives me a million error 2295 messages saying that "handle parameter or return type is not supported on a procedure in an [object] interface". Well, every one of my interface procedures has an int return type, and of course every one has an "[in] handle_t h" first argument (or else it would be unusable for RPC).
What am I missing here? Thanks.
|
|
|
|
|
Hi, I'm working with Visual Studio 2005 and C# 2.0. I would like to create a column that holds a custom control I created with a windows control library, it consists of 3 LinkLabels with different functionality each.
I actually don't know which class to derive to create my custom cell control. I tried with the DataGridViewTextBoxCell, DataGridViewLinkCell, DataGridViewButtonCell... but it didn't work, so I'd like to know if there's a way to create a column for a custom control which not derives from the custom columns that already exists.
Any help would be greatly appreciated.
|
|
|
|
|
I'm new to datagrids so if this seems easy my apologies. In my project the user enters a part number in a text box and then clicks a button. Based on what the user inputs the datagrid fills. I first got this to work with some code found from the net and help from users here on CodeProject:
namespace WebBasedPartsDB<br />
{<br />
public class WebForm2 : System.Web.UI.Page<br />
{<br />
protected System.Web.UI.WebControls.TextBox txtSearchPart2;<br />
protected System.Web.UI.WebControls.DataGrid DataGrid2;<br />
protected System.Web.UI.WebControls.Button btnSearch2;<br />
protected string strPartNumberInput2;<br />
<br />
public String strConnectSQL = (ConfigurationSettings.AppSettings["ConnectionString"]);<br />
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
if (!(Page.IsPostBack))<br />
{<br />
}<br />
}<br />
<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.btnSearch2.Click += new System.EventHandler(this.btnSearch2_Click);<br />
this.DataGrid2.SelectedIndexChanged += new System.EventHandler(this.DataGrid2_SelectedIndexChanged);<br />
this.Load += new System.EventHandler(this.Page_Load);<br />
<br />
}<br />
#endregion<br />
<br />
private void btnSearch2_Click(object sender, System.EventArgs e)<br />
{<br />
strPartNumberInput2 = txtSearchPart2.Text;<br />
string SQLString = "SELECT c.cost, pt.description, dd.DrawingNumber, dd.DrawingRevision, dd.DwgPath FROM costs c INNER JOIN Parts p ON c.PartID = p.Id INNER JOIN PartTypes pt on pt.ID = p.PartTypeID LEFT JOIN DraftingData dd on dd.PartID = p.ID WHERE p.PartNumber = @PartID";<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = new SqlConnection(strConnectSQL);<br />
cmd.CommandText = SQLString;<br />
cmd.Parameters.Add ("@PartID", strPartNumberInput2);<br />
BindGrid(cmd, DataGrid2);<br />
}<br />
<br />
<br />
private void BindGrid (SqlCommand command, System.Web.UI.WebControls.DataGrid DGrid)<br />
{<br />
SqlDataAdapter adapter = new SqlDataAdapter(command);<br />
DataSet ds = new DataSet();<br />
adapter.Fill(ds);<br />
DGrid.DataSource = ds;<br />
DGrid.DataBind();<br />
<br />
}<br />
<br />
private void DataGrid2_SelectedIndexChanged(object sender, System.EventArgs e)<br />
{<br />
<br />
}<br />
public void DataGrid2_edit (object sender, DataGridCommandEventArgs e)<br />
{<br />
DataGrid2.EditItemIndex = e.Item.ItemIndex;<br />
DataGrid2.DataBind();<br />
}<br />
<br />
}<br />
}
Question 1: Since using this "resuable" BindGrid I have to pass two parameters to it. So when I write the DataGrid2_edit (and will also have cancel and update) how do I write these so the BindGrid works properly? Would I have to declare the adapter and command in every function?
Okay, second part...started playing around with a BindData function found here on CodeProject that does not take on any parameters:
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Web;<br />
using System.Web.SessionState;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.HtmlControls;<br />
using System.Data.SqlClient;<br />
using System.Configuration;<br />
<br />
namespace WebBasedPartsDB<br />
{<br />
public class AddUpdatePart : System.Web.UI.Page<br />
{<br />
protected System.Web.UI.WebControls.Button btnGetPart;<br />
protected System.Web.UI.WebControls.DropDownList ddPartType;<br />
protected System.Web.UI.WebControls.DataGrid dgParts;<br />
protected string strPartNumberInputReference;<br />
protected System.Web.UI.WebControls.TextBox txtPartNumberInput;<br />
public String strConnectSQL = (ConfigurationSettings.AppSettings["ConnectionString"]);<br />
protected System.Data.SqlClient.SqlConnection sqlConnection1;<br />
<br />
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
}<br />
private void BindData()<br />
{<br />
strPartNumberInputReference = txtPartNumberInput.Text;<br />
SqlCommand sqlCmd = new SqlCommand("SELECT c.cost, pt.description, dd.DrawingNumber, dd.DrawingRevision, dd.DwgPath FROM costs c INNER JOIN Parts p ON c.PartID = p.Id INNER JOIN PartTypes pt on pt.ID = p.PartTypeID LEFT JOIN DraftingData dd on dd.PartID = p.ID WHERE p.PartNumber = @PartID", sqlConnection1);<br />
sqlCmd.CommandType = CommandType.Text;<br />
sqlCmd.Parameters.Add ("@PartID", strPartNumberInputReference);<br />
<br />
sqlConnection1.Open();<br />
dgParts.DataSource = sqlCmd.ExecuteReader();<br />
dgParts.DataBind();<br />
sqlConnection1.Close();<br />
<br />
}<br />
<br />
#region Web Form Designer generated code<br />
override protected void OnInit(EventArgs e)<br />
{<br />
InitializeComponent();<br />
base.OnInit(e);<br />
}<br />
<br />
private void InitializeComponent()<br />
{ <br />
this.btnGetPart.Click += new System.EventHandler(this.btnGetPart_Click);<br />
this.Load += new System.EventHandler(this.Page_Load);<br />
<br />
}<br />
#endregion<br />
<br />
private void btnGetPart_Click(object sender, System.EventArgs e)<br />
{<br />
<br />
BindData();<br />
}<br />
}<br />
}
But I get the error:System.NullReferenceException: Object reference not set to an instance of an object
So how do I fix one or the other? Is one approach better than the other?
Thanks again everyone for all your help!
|
|
|
|
|
<ToughLove>
Have you used the debugger to investigate what is null? I'm assuming not. My advice is to set a breakpoint inside your BindData method, run in Debug mode and step through the code until you find the culprit.
</ToughLove>
Josh
|
|
|
|
|
I want to send a set of arguments to a command line with my VC# app. Below is what i have. it will open the command window to the desired directory but i cannot figure out how to pass data to the command line so that i can run a bat file automatically. Can anyone help?
System.Diagnostics.Process Process = new System.Diagnostics.Process();
Process.EnableRaisingEvents = false;
string strCmdLine;
strCmdLine = FindFileLoc.Text;
Process.StartInfo.FileName = "cmd.exe";
Process.StartInfo.WorkingDirectory = strCmdLine;
Process.Start();
Process.WaitForExit();
Process.Close();
|
|
|
|
|
I think you would use the Arguments property which is in Process.StartInfo , like this:
Process.StartInfo.Arguments = strCmdLine Let me know if that does not solve the problem.
Also the WorkingDirectory field is to give the process a starting directory, so do not set it equal to strCmdLine .
Sincerely,
Alexander Wiseman
|
|
|
|
|
In addition to Alexander's answer...
If you are passing a string which contains spaces as a single command line parameter, you need to wrap that string in double quotes("). Otherwise the string is split into multiple parameters, which can cause some rather curious bugs.
For example:
proc.StartInfo.Arguments = "This is four parameters!";
proc.StartInfo.Arguments = "\"This is one parameter!\"";
Josh
|
|
|
|
|
sorry, strcmdline is the starting directory the actual command line arguments come from another field.
-- modified at 16:02 Thursday 15th June, 2006
|
|
|
|
|
No problem, I kind of realized that after I looked at your message again, but I left the note in my message because I thought you might be putting them together into one string (that is, both the started directory and the arguments).
Did the Arguments field work as you wanted it to?
Sincerely,
Alexander Wiseman
|
|
|
|
|
i added the arguments like this
process.StartInfo.Arguments = "argument"
also tried it like this
process.StartInfo.Arguments = "/"argument/""
still does not paste the argument to the command line.
|
|
|
|
|
I think everyone's confused on the terminology. From what I gather, you're opening up a command prompt and you want certain text to appear on the command prompt. This is different than command line arguments. In this case, I think you want to redirect standard input on the command prompt. If so, see my earlier post on this thread.
Logifusion[^]
|
|
|
|
|
I just tried using the Arguments property to call a batch file using the command shell (cmd.exe) and it worked. I think your problem may be in your command line arguments. Do you prefix the path to your batch file with the /C switch? If you look at the help for "cmd.exe" (you can do this by going Start > Run and typing: "cmd.exe /?"), you need the /C switch to execute a command with the shell.
For instance, if I have a batch file called "simple.bat" on the C: drive, then this command (even at the command prompt or the run dialog) will not run the batch file:
cmd.exe "C:\simple.bat"
Rather, you must enter the command this way:
cmd.exe /C "C:\simple.bat"
Thus, your Arguments property should look like this:
process.StartInfo.Arguments = "/C \"C:\\simple.bat\""
If you do not have the /C switch in there, then when you call the process cmd.exe, it will ignore your batch file argument. Let me know if that works.
Sincerely,
Alexander Wiseman
-- modified at 16:25 Thursday 15th June, 2006
[EDIT]
EricDV has posted a much quicker way of opening a batch file in his response below. However, if you positively need to do it with cmd.exe, then I think you'll need the /C switch.
[/EDIT]
|
|
|
|
|
|
|
If your goal is to run a batch file, then you should just set the .FileName to the batch file:
Process.StartInfo.FileName = "mybat.bat";
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
it will not run that way. You cannot double click the bat file you must open a command window and then type the name of the bat you wish to run.
|
|
|
|
|
Sorry, I didn't actually try it. That is odd. This will work though: (I tried it)
Process oProcess = new System.Diagnostics.Process();
oProcess.StartInfo.FileName = "cmd.exe";
oProcess.StartInfo.Arguments = "/C \"MyBat.bat\"";
oProcess.StartInfo.WorkingDirectory = "C:\\";
oProcess.Start();
oProcess.WaitForExit();
-- modified at 17:18 Thursday 15th June, 2006
[EDIT]
Alexander Wiseman beat me to this answer -> see above[^]
[/EDIT]
----------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I still can't get the command to run correctly. I have tried it use the process.startinfo.arguments and useing the redirectstandardinput methods and both produce the same results. the cmd.exe just flashes and no changes are made to the file that i am trying to change. i even tried leaving of the /C, when i do this the cmd.exe comes up and stays but does not paste the input to the command line. I am beginning to believe that i am just going to have to stick with the user inputting the data into the command window instead of the program.
<EDIT>
sorry i was leaving off the file extension because that is the way that is done when typed by a user. it works now thanks for all the help.
-- modified at 10:52 Friday 16th June, 2006
|
|
|
|
|
Hi,
In my application I have various SQL stored procedures (In SQL Server 2005) and now I want to add the tracing feature. If turned on, then print some informational lines onto a file stating the control path and if turned off, do not write to the file.
Is this possible by using the cool new feature "CLR Integration". If yes can anybody point me to some links. I have some basic knowledge of C# as well.
Thanks,
|
|
|
|
|
This sounds like a reasonable thing to do with an assembly hosted by SqlServer 2005, but I'm not sure if it's really necessary to jump through extra hoops just for simple logging. Could you not, for example, create a table which stores the log messages (instead of writing them to a file)? That would probably be more performant than calling into an assembly, plus, you could query that table in various ways - something not possible with pure text.
Just a thought...
Josh
|
|
|
|