|
Spooky - I went for that option and the client said 'no'. Their users need to know the option is there, and might become available soon, but isn't currently. The listbox shows servers with capacity below a certain threshold. When a threshold is reached, the server becomes 'unavailable' for that user, at which point I want the checkbox to be disabled. When a server is below capacity, a user can bag it by checking the listbox, which then 'disables' the server on other clients front end.
Looks like I will have to roll my own. Going for owner draw, dropping the list box and going for colours instead....Now, owner draw listboxes....hmmmm....back to google!
Thanks for your time anyway.
Regards
Angel
*********************************************
The sooner you fall behind, the longer you have to catch up.
|
|
|
|
|
I have a control over another control. The top one is tranparent.
I need to grab the pixels below. Anyone have any hints on grabbing a pixel color on a specific point in a panel?
Thanks,
Nick
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
If you're using 2.0, the Control class has the DrawToBitmap method. You could draw the control to a Bitmap, and then use the Bitmap's GetPixel() method to retrieve the color at that point. I doubt this will be very performant, though!
josh
|
|
|
|
|
Yeah , but that only works for the current bitmap.
I really need to grab what the screen shows and draw that pixel.
I guess I will just use the API to get that data. I was hoping to avoid that.
thanks
1 line of code equals many bugs. So don't write any!!
|
|
|
|
|
I have a small form that I spawn from another that acts as a way to edit a row of data from a typed DataTable. Within the load() method of the form, I execute this code.
<br />
mySource = new BindingSource();<br />
<br />
mySource.DataSource = myManagerClient.VersionTable;<br />
<br />
uxcbFMonth.DataBindings.Add("SelectedValue", mySource, "FiscalMonth");<br />
uxtextFYear.DataBindings.Add("Text", mySource, "FiscalYear");<br />
uxtextName.DataBindings.Add("Text", mySource, "VersionName");<br />
uxcbType.DataBindings.Add("SelectedValue", mySource, "Type");<br />
That works just fine and the data is all bound correctly. The problem is that it defaults to the first row of data in the sorted bindingsource. I have a foreign key value for the datarow I want to display, and I know I need to use the BindingSource.Position property to properly set the position I want to edit, but I'm having problems correctly finding the value to pass.
I tried using mySource.IndexOf(/*The DataRow using myManagerClient.VersionTable.Select()*/), that returned -1.
I also tried to use mySource.Filter(), but that filters the data in the main form as well (since I'm using Form.Show() instead of Form.ShowDialog()), and visually, I think that will confuse the end-user.
As far as I can tell at the moment, I'm going to have to manually pass through each row until I find the right one, but there really seems like there might be an easy way that I'm just missing.
Any ideas?
|
|
|
|
|
Found it, I needed to change the second line above to include .Select().
|
|
|
|
|
I'll try to be as clear as humanly possible, forgive me if my termonology is off, here goes...
I created a class library.
The class library consists of 2 classes.
Class 1 -> A form.
Class 2 -> a "gateway" class allowing me to modify the form.
Class 2 has 2 methods.
Each method spawns a new instance of the form and sets a few form properties.
Fairly easy so far right?
Here's a concept method of class 2.
<br />
public void ShowA(string defaultValue)<br />
{<br />
MainForm form = new MainForm();<br />
<br />
form.DefaultValue = Convert.ToDouble(defaultValue);<br />
form.Title = "A";<br />
form.picWindow.Paint += new PaintEventHandler(form.PaintA);<br />
form.Show();<br />
<br />
WindowsAPI.ActivateWindow("Form1");<br />
}<br />
Basically when I call this method, the form's picture box draws a line at an angle I specified. Then I re-activate my non-class library form using API (I'm not sure how to communicate between class library classes and non-class library forms -- this isn't the problem though).
So yeah...
Back to what I originally mentioned, I only want 1 instance of each form open. A and B can be open, but 2x As cannot be open. I was able to do this with more API, pretty much checking for the hWnd of the window based on its title.
Now, here's the problem...
If the form is currently open, instead of doing nothing (I told it to not to call the class 2 method if it detects an open window already) I want it to UPDATE the value of the current open form (it would draw a new line and update the picture box).
How in the world can I do this?
|
|
|
|
|
Use the singleton pattern[^] to ensure that only one instance of your Form type(s) exist. (You'll need to check in the singleton accessor that the Form has not been closed, if so, recreate it, etc.) Define a method on your Form which performs the update, and have Class2 call into that when the update needs to occur.
HTH,
Josh
|
|
|
|
|
Ok, but if you read my message you'd see I don't want to limit the form itself to 1 instance.
The problem isn't related to limiting it to 1 instance.
As stated in my original post, the problem at hand is being able to update a class library form, from my main application, if an instance of it exists.
I'm not sure how to...
1) Setup Class 2 (read OP) to "trigger" an update.
2) Declare the class library form so I can use its properties/methods (I can't use 'new', etc.).
|
|
|
|
|
"I only want 1 instance of each form open. A and B can be open, but 2x As cannot be open."
Sounds like a good place to use the Singleton pattern.
|
|
|
|
|
I should have been more clear, sorry. A and B are the same physical form. The form consists of a picture box.
I had 2 functions, ShowA() and ShowB().
As a quick example, let's say...
when I call ShowA(), the picture box's paint event would draw 1 black line.
when I call ShowB(), the picture box's paint event would draw 1 red line.
Same form, different picturebox contents.
|
|
|
|
|
Here is a possible way to solve your problem.
If you only want one instance of each form open at once, then why do you create a new form each time one of the methods is called? Instead, declare each of the form variables inside your class as private and then when one of the methods is called you can simply create the form if it does not exist already, or if it does exist, then you can simply call a method on it to update its information.
Here is how you would write it:
private MainForm formA;
private MainForm formB;
...
public void ShowA(string defaultValue)
{
if(formA == null)
{
formA = new MainForm();
formA.DefaultValue = Convert.ToDouble(defaultValue);
formA.Title = "A";
formA.picWindow.Paint += new PaintEventHandler(formA.PaintA);
formA.Show();
}
else
{
formA.SomeUpdateFunctionWhichYouCreate(defaultValue);
}
} Make a method similar for formB. In this way, you won't be creating the form every time and you'll be able to tell the form to update itself via a function that you create on the form.
Hope that helps!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Just read your other post in response to Josh. If you want to use the class without creating an instance of that class, then you need to make the variables and the functions which you wish to access static variables. My example will still work, just make the variables and the function static , like so:
private static MainForm formA;
private static MainForm formB;
...
public static void ShowA(string defaultValue)
... The thing to remember is that inside static methods, you can only access static variables of the class. This will not be a problem for you, however, since you want to use the class without creating instances of it, and therefore you will not have any instance variables.
Sincerely,
Alexander Wiseman
|
|
|
|
|
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
|
|
|
|
|