|
Hey everyone. Thanks in advance for any help. I have a WIN32 application that I am having difficulties with.
I basically have an ADD button for which you are able to add checkboxes at runtime. Then, I also have a REMOVE button which removes any checkboxes that are checked when the button is pressed. My difficulty lies in how to reference the checkboxes because they are all created at runtime. Here is some of my code.
<br />
function (int currentnumber) {<br />
<tab>myCheckBox = new System.Windows.Forms.CheckBox();<br />
this.panel1.Controls.Add(myCheckBox);<br />
myCheckBox.Location = new System.Drawing.Point(this.Group_label.Left-30, ystarter+(currentNumber*distance));<br />
myCheckBox.Name = "checkBox"+currentNumber;<br />
Console.WriteLine(myCheckBox.Name);<br />
myCheckBox.Size = new System.Drawing.Size(16, 24);<br />
myCheckBox.TabIndex = 6;<br />
}<br />
<br />
private void Remove_Group_Click(object sender, System.EventArgs e) {<br />
for(int i=1;i<=totalGroups;i++) { <br />
if (checkBox"+i.Checked == true) {<br />
this.panel1.Controls.Remove(checkBox"+i);<br />
}<br />
}<br />
}<br />
My REMOVE button click handler does not work properly. I can't get it to compile because it says that checkBox+i is not a valid Checkbox.
How do I reference my checkboxes that were created at runtime whose names should be:
checkBox1,checkBox2,....
Thanks again for any help.
|
|
|
|
|
That's not a valid variable name. You must enumerate your Controls and find a CheckBox with that name:
private Control GetControl(string name, bool caseInsensitive)
{
if (name == null) throw new ArgumentNullException("name");
foreach (Control c in Controls)
if (string.Compare(name, c.Name, caseInsensitive) == 0) return c;
return null;
} This returns a reference to a Control , so you can use the is statement to easily determine if it's a checkbox, or just recode the sample above to enumerate all Control s but in the conditional additionally use is to check if it's a CheckBox . Don't change Control c to CheckBox c (or something) because any control that is not a CheckBox will not cast and an exception will be thrown when enumerating.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can someone tell me what is wrong with this code.
I've got a couple of custom controls in a groupbox that i need to dispose. I tried the following foreach loop, but i get the error "Specified cast not valid".
foreach (WorkersCtrl c in groupBox.Controls)
{
c.dispose();
}
Thanks.
|
|
|
|
|
But that's very simple: at least one of the Control s in groupBox.Controls is not a WorkersCtrl .
The Controls collection holds Control s or derived classes, not limited to WorkersCtrl only.
If you really only want to call Dispose() then change WorkersCtrl c into Control c and you'll be fine.
mav
|
|
|
|
|
Thanks, it was pretty stupid of me. I've got it working now.
|
|
|
|
|
You must have a control inside the groupbox that is not of or inherit from WorkersCtl. You could try a couple of different things. You could either throw an if statement in there, to determine if the object is of type WorkersCtrl, and just use the object base class inside your for each decleration. Or...., you could change workersctrl to object, and set a debug statement within the foreach statement, outputing each objects .gettype().tostring() to determine which object is throwing the invalid cast error.
|
|
|
|
|
Hi all,
I have a problem concerning Crystal Report's performance on Win2000.
I use datasets to push data into my report, but the assignment of the datasource to the report and the the creation of the report take way too much time on some Win2000 systems.
Here are the two code snippets that take so much time:
report.SetDataSource(dataSet);
ReportForm reportForm = new ReportForm(report, m_ResourceManager);
reportForm.Show()
Some examples of the performance of this code:
On my Windows XP:
SetDataSource: 3 seconds
show report: 2 seconds
A colleague's Win 2000:
SetDataSource: 2 seconds
show report: 2 seconds
Another colleague's Win 2000:
SetDataSource: 105 seconds
show report: 391 seconds
My application runs fine on every Windows XP that I tested and it also runs fine on some Win2000 systems.
But unfortunately there are some Win2000 systems that have very bad performance running my app.
I have no clue what could be the reason for this.
For example:
The Win2000 system's load is at about zero percent, when it is waiting for the SetDataSource method to return.
How can this be?
Any help appreciated.
Best regards
Bernd R.
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
While Crystal Reports is not the most stable product in the computing world, I doubt this is the cause of your problem. I'd check first the database connections and/or the ammount of data that is being trasnferred on the slow machines.
Yes, even I am blogging now!
|
|
|
|
|
Database connection shouldn't be the problem, because there is no database. I use datasets!
And the amount of data transferred is not very high.
I also don't think that the hardware is the problem, because we use computers with Pentium4 2,8GHz and 512 MB of RAM.
I guess this must be some weird configuration issue
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
Hi,
I am using a Stored Procedure to validate Login Process:
Stored Procedure is defined as follows :
----------------------------------------------------------
CREATE PROCEDURE spCheckLogin
@LoginID char(20), @Pwd char(8), @Response int OUTPUT
AS
IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd)
Return 1
ELSE
Return 0
GO
----------------------------------------------------------
In C#, I am accessing this Stored Procedure as follows:
try
{
string temp="";
//open the connection
gvDatabase.scInventoryControl.Open();
//create the sql
sql = "spCheckLogin";
//create command
cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl);
cmdLogin.CommandType=CommandType.StoredProcedure;
cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20);
cmdLogin.Parameters["@LoginID"].Value=log;
cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8);
cmdLogin.Parameters["@Pwd"].Value=p;
cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4);
cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output;
Console.WriteLine("Data Access started");
cmdLogin.ExecuteNonQuery();
temp = cmdLogin.Parameters["@Response"].Value.ToString();
Console.WriteLine(temp);
//clean up code
cmdLogin.Dispose();
gvDatabase.scInventoryControl.Close();
Console.WriteLine("Data Access Closed");
}
catch(Exception ex) { Console.WriteLine(ex.ToString() ); }
------------------------------------------------------------
However It doesn't print any values, although I values do exists in the table
What am i doing wrong?
ThANX in ADvance
|
|
|
|
|
looks to me you got two thing mixed up.
you should eighter change youre sql code to
=======================
CREATE PROCEDURE spCheckLogin
@LoginID char(20), @Pwd char(8), @Response int OUTPUT
AS
IF EXISTS (SELECT * FROM tEmployees WHERE LoginID=@LoginID AND Pwd=@Pwd)
SET @Response=1
ELSE
SET @Response=0
GO
========================
OR you should use something like this in youre code:
========================
string temp="";
//create the sql
string sql = "spCheckLogin";
//create command
cmdLogin = new SqlCommand(sql,gvDatabase.scInventoryControl);
cmdLogin.CommandType=CommandType.StoredProcedure;
cmdLogin.Parameters.Add("@LoginID", SqlDbType.Char,20);
cmdLogin.Parameters["@LoginID"].Value=log;
cmdLogin.Parameters.Add("@Pwd", SqlDbType.Char,8);
cmdLogin.Parameters["@Pwd"].Value=p;
cmdLogin.Parameters.Add("@Response",SqlDbType.Int,4);
cmdLogin.Parameters["@Response"].Direction=ParameterDirection.Output;
Console.WriteLine("Data Access started");
try
{
//open the connection
gvDatabase.scInventoryControl.Open();
//use the connection
temp=(string)cmdLogin.ExecuteScaler();
Console.WriteLine(temp);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString() );
}
finally
{
//clean up code
gvDatabase.scInventoryControl.Close();
Console.WriteLine("Data Access Closed");
}
cmdLogin.Dispose();
========================
i hope this helps.
(p.s. i did not test above code)
cookies are for eating, not for websites.
|
|
|
|
|
Try...
// Add the return value parameter
SqlParameter param = m_oCommand.Parameters.Add( "RETURN_VALUE", SqlDbType.Int );
param.Direction = ParameterDirection.ReturnValue;
D!shan
|
|
|
|
|
In namespace WindowsApplication1 I declare the richTextBox1 which I want to CALL FROM OTHER NAMESPACES MANY TIMES MAKING CHANGES that I want TO STAY. How I could make it for maximum performance ?
The first time I declared it as public static removing the keyword this in front of it.
But every time I was going to the Form1.cs[Design]* and I was making just a little change to the richTextBox1 the static was leaving and the this was appearing again.(Can I stop it happens?)
The second time I was passing the richTextBox1 as reference variable for many functions. But I think it is slow.(Is it realy slow?)
|
|
|
|
|
Your 'static' change is happening because the Windows Forms designer requires the controls on the form you're designing to be instance variables.
If you want, yes you can pass the rich text box into the functions you want to use it in. No, this is not slow, you're not copying the rich text box, just a small pointer to the rich text box.
A better solution is NOT to use static, and instead pass the rich text box once to the other class, then store that variable in the other class. For instance
class Form1
{
...
MyOtherClass theOtherOne = new MyOtherClass(this.richTextBox1);
}
class MyOtherClass
{
private RichTextBox theRichTextBox = null;
public MyOtherClass(RichTextBox rtb)
{
theRichTextBox = rtb;
}
void DoSomething()
{
theRichTextBox.Text = "hey I've modified it from another class";
}
}
#include "witty_sig.h"
|
|
|
|
|
Thank you very much Judah Himango !!!
|
|
|
|
|
Hi all
i need to programming a menu like Windows Start menu please can any one help me with example.
|
|
|
|
|
The simplest way is to add a Button to your container (like a Form or UserControl ) and a ContextMenu that is either defined with the MenuItem s you want, or adds them dynamically in the ContextMenu.Popup event handler. In the handler for the Button.Click event (inheritted from Control ), call ContextMenu.Show , passing the Button that was clicked and some Point , like the X and Y coordinates of the mouse position (remembering to transform the coordinates into client coordinates using Control.PointToClient ) or some corner of the Button (like new Point(0, 0) for the upper-left corner, since the coordinates are relative to the control you pass in the first parameter).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your Reply
do you know menu in Visual Studio dot net in the left i named Docking Menu or striping menu .i need to do one like this . . .please help with example or ready made component
Thanks for your Time and help
Regards
Haytham
|
|
|
|
|
Try searching this web site. There are plenty of examples. That's what this site is for.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i Searched in the site put i cant find any example met me need can you find a one for me
Thanks
best regards
|
|
|
|
|
Hi,
I just starting to play around with managed Direct X. What I want to do is create an application which has a windows form with a PictureBox containing Direct3D graphics but I'm having trouble getting started. I tried setting passing the PictureBox control to the constructor for Device and then simply blanking it to a uniform blue (borrowing code from tutorial 1 in the SDK documentation). I was calling the Render() method to do the rendering on the OnPaint event but nothing seems to be happening - the picture box remains defiantly grey!. What am I missing here?
What I'd ideally like to do is create a custom Direct3DPictureBox control inheriting from PictureBox so I can drop it into my apps without worrying about them too much.
Thanks
"Where do we go to get our good name back?...we go where we always go when a dramatic change is needed. We go to the ballot box" - Al Gore 5/26/04
|
|
|
|
|
Please i need helping in TAPI application ?
i am student ,and i want to work on some telephony application
i know that the perfect subject is TAPI ,but there are some questions :-
1- can i use the TAPI in c# language ?
2- should i install some files or dll files that help to execute TAPI functionallity ?
3-couild i have an example in c# that shows me how exactly work with TAPI in c#?
finally ,forgive me for my bad english?
|
|
|
|
|
What was wrong with the responses that Michael and I gave you the other day? No one is going to do this work for you.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I need to put toolbar item to my windows application to make the selected text subscript or when it pressed , typed letters or numbers will be subscript.
I searched more about this topic on the net but I can only find some this:
myRichTextBox.ToolbarLayout = "bold,superscript,subscript";
but doesnt work there is no option in the Richtextbox class like "ToolbarLayout"...
any help..I would be glad...thanks
|
|
|
|
|
Unfortunately, MS didn't expose all the functions of the RichText control for .NET.
You can do something like richTextBox1.SelectionBold = true but there's no such thing as richTextBox1.SelectionSubScript = true
But since the .NET RichTextBox in fact just wraps the Win32 RichEdit control you can use the structs and messages for this control to achieve subscript, superscript, various underline styles and so on.
Take a look at this article here, I've added something similar to the RichTextBoxEx class already (look towards the end of the article).
This can be easily modified to add subscript/superscript formatting for a selected range od text.
Regards,
mav
|
|
|
|