|
I can think of another way to do it, but it's a bit longer:
1- Create the text box.
2- Parse it into a float to validate the input
3- Format the float with your desired format into a string
4- Do whatever you want with that string
The code I used is like this:
float test = float.Parse(textBox1.Text);
MessageBox.Show(test.ToString("#,###.##") + "%");
|
|
|
|
|
Use apostrophes in the format string to specify literal text:
"#,##0.##'%'"
---
b { font-weight: normal; }
|
|
|
|
|
|
I don't know if it's a bug or not but i have a listbox with some items in there. on the click event of the listbox i put a while loop. what happens is that the listbox automatically highlite the last item. You can test that on ur VS2005. Is there a way to fix that?
Donkaiser
|
|
|
|
|
Hello donkaiser.
You might want to post the code of the vent handler, so that perhaps we could understand the problem more.
|
|
|
|
|
sorry i should have done that. i guess im not very descriptive.
private void listBox2_Click(object sender, EventArgs e)
{
bool inf = true;
do{
Application.DoEvents();
Debug.WriteLine("looping");
}while(inf);
}
and add some items to your listbox. You will see that it keeps selecting the last item automatically no matter what you do.
Donkaiser
|
|
|
|
|
Hello
First:
You must have noticed that your loop goes forever. Are you sure you want that?
Second:
Your problem is because your listbox captures the mouse each time your loop goes. Try this code:
private void listBox2_Click(object sender, EventArgs e)
{
bool inf = true;
do{
listBox2.Capture = false; //To release the mouse
Application.DoEvents();
Debug.WriteLine("looping");
}while(inf);
}
But again this loop will go forever. If that is your exact code, I hope you reconsider it.
|
|
|
|
|
I want to create a hatch brush using as hatch style a string ... for example "BackwardDiagonal"
how can I do something like :
HatchBrush hb = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Red);
using only the string "BackwardDiagonal" ?
modified 30-Nov-21 21:01pm.
|
|
|
|
|
Well, you could either use Reflection (I haven't done this myself), or you would need to parse your string in the constructor:
public HatchBrush(string type, Color color)
{
switch(type)
{
case "BackwardDiagonal":
return new BackwardDiagonalBrush(...);
default:
return new SomeDefaultBrush(...);
}
}
However, this isn't as flexible as the Relfection approach
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
with switch and case it would take some time because I want to have multiple choices (over 10 or 20)
I'll consider finding more about Relfection .
Thanks a lot.
modified 30-Nov-21 21:01pm.
|
|
|
|
|
You can use Enum.Parse to do this
HatchBrush b = new HatchBrush((HatchStyle)Enum.Parse(typeof(HatchStyle),"BackgroundDiagonal"),Color.Gray,Color.LightGray);
|
|
|
|
|
Problem solved
Thanks a lot.
modified 30-Nov-21 21:01pm.
|
|
|
|
|
Why do I get an error saying "Input string was not in correct format" when I do the following?
sb.AppendLine(string.Format("\t\t\tpublic static string {0}TableName { get { return \"{0}\"; } }", tr.TABLE_NAME));
sb is a stringbuilder
tr.TABLE_NAME is a string
I'm thinking that it is probably something to do with the curly braces in there, almost like it expects a date format string or something in there.
I know the code is ugly, but it's just for a little quick utility.
|
|
|
|
|
Apparently, you have to escape a single "{" with another "{". You also have to do this with the closing braces.
|
|
|
|
|
Well, it's definitely the curly braces. That's confusing the Format method. When you want to put a '{' in the string use '{{'.
Logifusion[^]
|
|
|
|
|
Hi.
I'm new to C# but want to learn.
Can someone tell me how to implement (where to enter code mentioned below) a single process instance object that I found on:
http://www.codeproject.com/csharp/cssingprocess.asp?&forumid=11773
I can make that work, but then I don't see title bar of my program, so I'm sure I'm missed up somewhere
Thanks in advance.
|
|
|
|
|
I'm not sure where your problem is. Create a new windows application project in visual studio. Download the code that goes with the article you have. It's a CS file. Add that to your project. Make sure the namespaces are the same. Look in the Form1 code and find the Main method and add the following (as detailed in the article):
using(SingleProgramInstance spi = new SingleProgramInstance())
{
if (spi.IsSingleInstance)
{
Application.Run(new Form1());
}
else
{
spi.RaiseOtherProcess();
}
}
Logifusion[^]
|
|
|
|
|
I want to check the input to a text box is numeric (e.g., mmddyyyy). Is there a command for this?
sas
|
|
|
|
|
If you're using framework 2.0 you could use DateTime.TryParse or the MaskedTextBox . Otherwise use DateTime.Parse .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Int.TryParse
Will return true if the string is a number
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello again all. I found an example of a fully editable datagrid that was attached to the Northwind database. I have been tinkering with it to use with my own data. The code uses the Microsoft SQL Helper.cs class.
Originally the code opened the page, and returned all the employees in the NW database. I ran the project and everything was fine.
Original code:
private void BindData()<br />
{<br />
ds = new DataSet();<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
DataGrid1.DataSource=dt;<br />
DataGrid1.DataBind();<br />
<br />
}
I changed it to take a parameter. The user enters a part number in a text box, and clicks a search button and then I want the datagrid to populate. It returns 3 blank rows. When I went through the debugger it looks like it tries to run through the SQLHelper code before it looks at the button click function.
I think it has to do with how I'm sending the parameters but I'm not sure because if I change the stored procedure and code for no parameters, it works.
Current code:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest", param);<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
Does anyone have any ideas? I didn't post the SQLHelper code as it is LONG but if someone is willing to help and needs it let me know.
Thanks again to all who help!
|
|
|
|
|
So it looks like changing the ExecuteDataset() call resolved your previous problem?
leckey wrote: if I change the stored procedure
Did you test the sp with the parameter in your Database environment?
|
|
|
|
|
Yes, changing the ExecuteDataset to use Command.StoredProcedure got rid of the previous error.
I did test the sp with a parameter.
SP with parameter:
CREATE PROCEDURE [dbo].[GetPartInfoTest]<br />
@PartInfo varchar<br />
<br />
AS<br />
SELECT * FROM Parts<br />
GO
BindData with parameter:
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest", param);<br />
<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
DataBind without parameter
private void BindData()<br />
{<br />
strPartNumberInputReference = txtSearchPart.Text;<br />
ds = new DataSet();<br />
SqlParameter param = new SqlParameter("@PartID", strPartNumberInputReference);<br />
ds=SqlHelper.ExecuteDataset(this.connectionString, CommandType.StoredProcedure, "dbo.GetPartInfoTest");<br />
Session["ds"]=ds;<br />
dt = ds.Tables[0];<br />
Session["dt"]=dt;<br />
dgParts.DataSource=dt;<br />
dgParts.DataBind();<br />
txtSearchPart.Text = "";<br />
<br />
}
|
|
|
|
|
The problem might be that your SP declares the parameter as @PartInfo, but you are creating an SqlParameter whose Name is @PartID.
|
|
|
|
|
Okay, got my names matching.
I commented out the BindData call in th Page_Load
private void Page_Load(object sender, System.EventArgs e)<br />
{<br />
<br />
if(!Page.IsPostBack)<br />
{<br />
}<br />
<br />
}
So now I don't get three blank lines. But I don't get the data to return either. So I think my problem is how I'm setting up the page_load.
|
|
|
|