|
hi,
i'm using Component One TrueDBGrid in my form.
one of the columns is the "Amount" field. ItShould allow users to enter only integers or float type. But if he attempts to enter characters, error provider should be shown..this will be done in RowColChange event of the grid...so he shuld not be able to enter any characters or special characters..
Please tell me how i'll do this...i tried using the EditMask property of the grid i.e.
tdbgridOnewayReturn.Splits[0].DisplayColumn[3].DataColumn.EditMask = "0000000.00";
but this doesn't take decimal..if i enter 0000332.99, then it saves as 3329900..which is not correct.
But if i use NumberFormat property of the grid :
tdbgridOnewayReturn.Splits[0].DisplayColumns[3].DataColumn.NumberFormat = "Fixed";
then,the user can also enter characters..which is not correct..
please do tell me how i'll resolve this problem....
thanx ..
|
|
|
|
|
I am having trouble writing an arraylist in the console. Below is the code, I believe everything is working well, but I have no way of writing the array. Any help would be appreciated!
using System;
using System.Collections;
public class PrimeFinder
{
public static void Main()
{
// Creates and initializes the prime number array
ArrayList primeNumbers = new ArrayList();
for(int i = 2; i < 100; i++)
{
bool divisible = false;
foreach(int number in primeNumbers)
if(i % number == 0)
divisible = true;
if(divisible == false)
primeNumbers.Add(i);
}
// Display the prime number list
}
}
|
|
|
|
|
Is this what you need ?
foreach(int num in primeNumbers)<br />
Console.WriteLine(num );
|
|
|
|
|
>>created a checkbos and a button like this:
CheckBox checkBox2 = new CheckBox();
checkBox2.Text="Test";
checkBox2.Location = new System.Drawing.Point(16,64);
//create the button
btnPF.Text="Create";
btnPF.Location = new System.Drawing.Point(208,208);
btnPF.Click += new System.EventHandler(btnPF_Click);
>> on the event I place this code
if(checkBox2.Checked==true)
MessageBox.Show("checked","Info";
else
MessageBox.Show("Not checked","Info");
>>problem, even if the box is checked, the message is always "Not Check"
>>Any help is greatly appreciated
|
|
|
|
|
First, you don't need the first 8 lines of code you posted, it's automatically generated by the VS.NET designer, and the default control code is generated by double-clicking the control in the designer view. Other than that, the control should read something like this:
<br />
public void btnPF_Click(object sender, EventArgs e)<br />
{<br />
if (checkBox2.Checked)
{<br />
MessageBox.Show("Checked", "Info");
}<br />
else<br />
{<br />
MessageBox.Show("Not checked", "Info");<br />
}<br />
}<br />
So, in short, use the VS.NET designer to generate any code except for the code inside the main scope in the code above (the '{}' that is opened first and closed last), using the the drag and drop to the designer method to make the controls, and double-clicking them to add code to them.
|
|
|
|
|
Thank you jamac7142;
I did not explained correctly so let me try again:
I have one button (btnCreate)on form, when it is clicked, it creates three components, a panel, checkbox and another button (btnPF). When the new button (btnPF)is clicked, it checks if the checkbox is checked or not.
So the 8 lines are part of the first button (btnCreate).
|
|
|
|
|
Try this then:
<br />
private void btnCreate_Click(object sender, EventArgs e)<br />
{<br />
Panel panel1 = new Panel();<br />
CheckBox cB1 = new CheckBox();<br />
Button btnPF = new Button();<br />
<br />
<br />
panel1.Location = new Point(x,y);<br />
panel1.Size = new Size(x,y);<br />
<br />
cB1.Location = new Point(x,y);<br />
cB1.Size = new Size(x,y);<br />
cB1.Text = "checkBox";<br />
<br />
btnPF.Location = new Point(x,y);<br />
btnPF.Size = new Size(x,y);<br />
btnPF.Text = "button";<br />
<br />
Controls.Add(panel1);<br />
Controls.Add(cB1);<br />
Controls.Add(btnPF);<br />
<br />
this.btnPF.Click += new System.EventHandler(this.btnPF_Click);<br />
}<br />
private btnPF_Click(object sender, EventArgs e)<br />
{<br />
if (cB1.Checked)<br />
{<br />
MessageBox.Show("Checked", "Info");<br />
}<br />
else<br />
MessageBox.Show("Unchecked", "Info");<br />
}<br />
-- modified at 0:16 Saturday 29th October, 2005
|
|
|
|
|
You code is just like mine with the exception of the line adding the controls:
panel1.Controls.AddRange(new Control[]{cB1,btnPF});
I changed to your sugetion, just incase
// Add them:
Controls.Add(panel1);
Controls.Add(cB1);
Controls.Add(btnPF);
but
Still no luck.
somehow does not like the "if (cB1.Checked)...."
it alsways displays the message under "else"
|
|
|
|
|
Try this:
<br />
if (checkBox1.Checked)<br />
{<br />
MessageBox.Show("Checked");<br />
}<br />
else<br />
{<br />
MessageBox.Show("Unchecked");<br />
}<br />
|
|
|
|
|
Thank you jmac7142 for helping me troubleshoot this problem.
An tried the MessageBox as you suggested.
still no luck.
I am planning to use about five checkboxes but I can even make it work with one. May be I should the "switch" insted of the "if-else"
|
|
|
|
|
My last post worked on my machine though...
|
|
|
|
|
Guessing from your recent question about the NullReferenceException, could it be that you've messed up the controls you're working with, i.e. create one CheckBox and then test the wrong one for its Checked state?
You don't have to try switch instead of if-else, they're completely equivalent and will definitely not be the reason for your problem.
Try setting a breakpoint at where you query your CheckBox and take a look at its properties. Perhaps you can find the reason there.
Regards,
mav
|
|
|
|
|
How to solve viewing images with zoom in C# like in very common graphic editors? There you just open an image, and then view desired detail of an image (using Magnyfying glass tool). When you zoom it in, you see pixelated part of image and smaller scroll bars, so you are still able to move image.
In C#, when I try to stretch 3 megapixel image to 800%, an ugly memory problem appears. Why? I'm not resizing the image, just stretching PictureBox to see zoomed image. But this technique doesn't work. Does anybody know how to solve this? I'm lost with this task
|
|
|
|
|
Hello,
I'm trying to read data from a binary file with multiple resources that each have their own header, containing the distance to the next resource header as well as a uInt32 that needs to be read. My question is this: is it possible to read data from each resource header, keeping in mind that since this is a file type in general, and the distance to the next resource will be different for each file or resource that the user opens.
Thanks in advance.
|
|
|
|
|
Yes, of course it is possible. There wouldn't be much point of using a file format that couldn't be read, would it?
---
b { font-weight: normal; }
|
|
|
|
|
I'm aware of that, but do you have any ideas as to how?
|
|
|
|
|
You described how to read the file, what is the problem really?
---
b { font-weight: normal; }
|
|
|
|
|
What would be a good way to read the file's resource headers?
|
|
|
|
|
Hello Everybody!!!
I have one problem parsing Xml file iam using the following sheet for the xml file of mine as the code below.
<code>
<article>
<letter from = "my email address">
<subject>any subject here</subject>
<paragraph>any paragraph</paragraph>
</letter>
</article>
</code>
Now from the code above it is simple xml file but i want to know how can i retrieve the attribute value which is the email address from the attribute "From".
I know how can i access subject and paragraph but i want to know how can i access the values of attributes please any one can give me example with code please to understand how can i do such actions.
Please everybody Help me with this problem please.
Iam so appreciateful for you all.
Thanks everybody.
Mess With The Best And Die Like The Rest
-- modified at 17:05 Friday 28th October, 2005
|
|
|
|
|
Hi there,
You can use XPath quere to retrive value of attribute
Take a look on this article
Xml
<< >>
|
|
|
|
|
|
I am trying to write a function that will return the reference of a textbox control on a form. I come from a classic VB background. The questIon i have is how do i pass around a control in a variable? In VB, i could put the control in a generic Textbox variable and pass it around. But when i do this in C# nothing seems to happen. I am unable to change the textbox properties. What is the HowTo for C#? Thanks.
private void LoadCellMatrix()
{
int row;
int col;
System.Windows.Forms.TextBox textboxRef;
for(row = 1; row <= 4; ++row)
{
for(col = 1; col <= 4; ++col)
{
textboxRef = ReferenceCell(row, col);
textboxRef.Text = "TEST" + row + ", " + col;
}
}
}
private System.Windows.Forms.TextBox ReferenceCell(
int row,
int col)
{
string cellName;
cellName = "txtRow" + row + "Col" + col;
System.Windows.Forms.TextBox textboxRef;
// get compile error if i do not assign to something
textboxRef = this.txtRow1Col1;
switch(cellName)
{
case "txtRow1Col1":
textboxRef = this.txtRow1Col1;
break;
case "txtRow1Col2":
textboxRef = this.txtRow1Col1;
break;
}
return textboxRef;
}
|
|
|
|
|
redfish34 wrote: switch(cellName)
{
case "txtRow1Col1":
textboxRef = this.txtRow1Col1;
break;
case "txtRow1Col2":
textboxRef = this.txtRow1Col1;
break;
}
I assume that second case is supposed to read textboxRef = this.txtRow1Col2; ?
What you are doing should work. You declare a TextBox variable and give it a reference to the TextBox you're interested in. What exactly do you mean by nothing happens?
|
|
|
|
|
The "nothing" problem was that the first textbox would not update with any text. After fiddling around with the code and recompiling- not really changing anything- everything magically works now. I had this experience with classic VB and ASP. Sometimes things just don't work- then later would work. You scratch your head for hours wondering what the heck you are overlooking. Since i am new to C# i was not sure if the problem was me or the microsoft IDE. I guess i am going to have to get in the habit of recycling the computer power when i run in "mysterious" circumstances again. This is one way to overcome these glitches. FYI, i am using visual studio 2003.
But thanks very much for confirming that i did good. I posted this question on some other forums and got ZERO response. Your help allowed me to rule out "me" as the problem.
|
|
|
|
|