|
First check if the Text value is numeric before trying to convert it.
This can be done with a RegEx , or Char.IsNumeric
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
thanks for reply! J4amieC
Char.IsNumeric
is fine for a character, while i'm working with textbox string.
uroojkhan
|
|
|
|
|
try{<br />
int stocktype = Convert.ToInt16(tbStockTypeId.Text);<br />
if(stocktype <= 0) { <br />
}<br />
}<br />
catch(FormatException fexc){<br />
Messagebox(tbStockTypeId.Text + "Is not a number");<br />
}
Coulda, woulda, shoulda doesn't matter if you don't.
[MODIFIED]In this 32 bit world, use ToInt32 unless you have little memory.[/MODIFIED]
<marquee>
-- modified at 10:53 Friday 26th May, 2006
|
|
|
|
|
Although that would work absolutely fine, its generally considered bad practice to control program flow with exceptions.
Exceptions for exceptional behaviour - the user making an invalid entry is not exceptional, it is expected!
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
J4amieC wrote: the user making an invalid entry is not exceptional, it is expected
He he , I agree on this, but I don't understand why using try/catch is bad practice?
Coulda, woulda, shoulda doesn't matter if you don't.
<marquee>
|
|
|
|
|
I guess because throwing exceptions is just more resource intensive, its a lot quicker to first check if the value is valid.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
mja, sounds reasonable.
tnx.
Coulda, woulda, shoulda doesn't matter if you don't.
<marquee>
|
|
|
|
|
thanks V!
about Exceptions agree with J4amieC.
Do remember (for Int16 and Int32) What u required is more important than what u have!
Regards,
uroojkhan
|
|
|
|
|
If you are using .NET 2.0 - why not use Int32.TryParse()?
<br />
short outint;<br />
if (!Int16.TryParse(tbStockTypeId.Text, out outint)) {<br />
throw new ArgumentException("Argument is not integer", "tbStockTypeId");<br />
}<br />
____________________________________________
Robin Panther http://www.robinland.com
|
|
|
|
|
with a lot of thanks Robin Panther!
its solved my problem.
Do remember (for Int16 and Int32) What u required is more important than what u have!
Regards,
uroojkhan
|
|
|
|
|
hi all,
is there something wrong with this code ?
DataTable dset1 = new DataTable();
string myconnection = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=veritabani.mdb";
conn = new OleDbConnection(myconnection);
adp1 = new OleDbDataAdapter("Select * From Users", conn);
adp1.Fill(dset1);
conn.Open();
txtusername.DataBindings.Add("Text", dset1, "username");
txtpassword.DataBindings.Add("text", dset1, "password");
CurrencyManager addnewentry = (CurrencyManager)this.BindingContext[dset1];
addnewentry.AddNew();
conn.Close();
MessageBox.Show(" new user inserted!");
i get no error during processing codes above but i couldnt see the new row (new user and password) on access ?
where i am doing wrong ?
help please ...
|
|
|
|
|
i think u r opening connection late
u should put conn.Open() before
adp1 = new OleDbDataAdapter("Select * From Users", conn);
sorry i forgot that datadapters fill method opens the conection
expicitly so this might not be couse.
rahul
-- modified at 8:13 Friday 26th May, 2006
|
|
|
|
|
Hi
how do you implement the right arrow to configure a custom control in desing time.
As a example the DataGridView allow you to edit a colums or add a column, select the datasource...
Send me a how to do or a web address would be fine.
thanks
K
|
|
|
|
|
Hi,
how can I show the "Internet Options" dialog on my WinForm with C#,
Like in Internet Explorer? I Use Visual Studio 2005 and the .Net Framework 2.0.
Can I have some helpfull code?
Thank's
best regard
Adiphe
"...all is simple, but there is always simpler ..."
-- modified at 6:56 Friday 26th May, 2006
|
|
|
|
|
check out these links
http://support.microsoft.com/?kbid=329014
or
http://www.kbalertz.com/815716/invoke.dialog.Source.dialog.Internet.Options.dialog.WebBrowser.control.aspx
first one wasnt working on my browser for some reason, both are same articles.
Shajeel
|
|
|
|
|
Thank's Shajeel,
But I don't want to use all this ActiveX elements from the COM components.
Can we find a better simpler code for .Net 2.0?
best regard
Adiphe
"...all is simple, but there is always simpler ..."
|
|
|
|
|
try this
System.Diagnostics.Process.Start("C:\\Windows\\System32\\rundll32.exe", " shell32.dll,Control_RunDLL inetcpl.cpl,,0");
Shajeel
|
|
|
|
|
Thank's a lot Shajeel for your reply!
I have try it, also with
System.Diagnostics.Process.Start("rundll32.exe", " shell32.dll,Control_RunDLL inetcpl.cpl,,0");
Both are realy very simple and it's work!
Thanks
best regard
Adiphe
"...all is simple, but there is always simpler ..."
|
|
|
|
|
i wanna clone a mdi child form when user click the "clone" button.
How can i do ?
|
|
|
|
|
There is no simple function in the framework to do this. Thus you will have to make it yourself. If you give some further informations on what is contained in your form whe might be able to give you some advice on how to start.
Generally speaking you will have to create a new instance of the form and copy everything what is not generated in the constructor/InitializeComponent from the old to the new form.
|
|
|
|
|
i'm having problems with treeview updating.
i'm trying to redraw the tree so that it reflects an ArrayList of servers and devices. below is my code.
sorry about the parsing. will try to come back and fix it up.
public void TreeRefresh()
{
this.m_tvTree.BeginUpdate();
this.m_tvTree.ExpandAll();
PruneTreeBranches();
GrowTreeBranches();
this.m_tvTree.ExpandAll();
this.m_tvTree.EndUpdate();
}
private void PruneTreeBranches()
{
TreeNode tn = this.m_tvTree.TopNode;
while(tn != null)
{
if(tn.Tag.ToString().IndexOf("s") == 0)
{
string ip = tn.Tag.ToString().Substring(2);
CServer server = m_Servers.GetServer(ip);
if(server == null)
{
DeleteTreeNode(tn);
tn = this.m_tvTree.TopNode;
continue;
}
}
else if(tn.Tag.ToString().IndexOf("d") == 0)
{
string ip = tn.Tag.ToString().Substring(4);
CServer server = m_Servers.GetServer(ip);
if(server == null)
{
DeleteTreeNode(tn);
tn = this.m_tvTree.TopNode;
continue;
}
int port = Convert.ToInt32(tn.Tag.ToString().Substring(2,1));
CDevice device = server.FindDevice(port);
if(device == null)
{
DeleteTreeNode(tn);
tn = this.m_tvTree.TopNode;
continue;
}
}
else
{
DeleteTreeNode(tn);
tn = this.m_tvTree.TopNode;
continue;
}
tn = tn.NextVisibleNode;
}
}
private void DeleteTreeNode(TreeNode tn)
{
this.m_tvTree.Nodes.Remove(tn);
}
private void GrowTreeBranches()
{
if(this.m_bShowServers)
{
for(int ii = 0; ii < m_Servers.Count; ii++)
{
CServer server = (CServer)m_Servers[ii];
GrowServerBranch(server);
}
}
else
{
for(int ii = 0; ii < m_Servers.Count; ii++)
{
CServer server = (CServer)m_Servers[ii];
for(int jj = 0; jj < server.Devices.Count; jj++)
{
CDevice device = (CDevice) server.Devices[jj];
TreeNode dn = GrowDeviceBranch(device, server.IpAddress);
if(IsNew(dn.Tag.ToString()) == null)
this.m_tvTree.Nodes.Add(dn);
}
}
}
}
private void GrowServerBranch(CServer server)
{
TreeNode tn = IsNew("s "+server.IpAddress);
if(tn == null)
{
tn = new TreeNode();
tn.Tag = "s " + server.IpAddress;
tn.SelectedImageIndex = 5;
tn.ImageIndex = 5;
this.m_tvTree.Nodes.Add(tn);
}
if(server.ServerAlias == server.DefaultAlias)
tn.Text = server.ServerAlias + ": " + server.IpAddress;
else
tn.Text = server.ServerAlias;
for(int ii = 0; ii < server.Devices.Count; ii++)
{
TreeNode dn = GrowDeviceBranch((CDevice)server.Devices[ii], server.IpAddress);
if(IsNew(dn.Tag.ToString()) == null)
tn.Nodes.Add(dn);
}
}
private TreeNode GrowDeviceBranch(CDevice device, string ip)
{
TreeNode tn = IsNew("d "+device.Port+" "+ip);
if(tn == null)
{
tn = new TreeNode();
tn.Tag = "d "+ device.Port + " " + ip;
}
tn.Text = device.Manufacturer + " - " + device.ModelNumber;
tn.SelectedImageIndex = device.Status.Status;
tn.ImageIndex = device.Status.Status;
return tn;
}
private TreeNode IsNew(string mCheck)
{
TreeNode tn = this.m_tvTree.TopNode;
while(tn != null)
{
if(tn.Tag.ToString() == mCheck)
return tn;
tn = tn.NextVisibleNode;
}
return null;
}
|
|
|
|
|
I have an application that has 3 panels one on top of the other.
Each panel contains several control.
I also have a toolbar that I am using to navigate between the panels using the SendToBack() and BringToFront() methods and with the Hide() and Show() methods.
For some reason when I want to show the the 3rd panel, I get the controls of the first panel together with the 3rd panel.
This problem doesn't happen when I display the 2nd panel or the first panel.
Help will be appreciated.
Topaz
P.S.
this is the code:
switch(e.Button.Text)
{
case "Option 1":
this.panelOption2.SendToBack();
this.panelOption3.SendToBack();
this.panelOption1.BringToFront();
this.panelOption1.Show();
this.panelOption2.Hide();
this.panelOption3.Hide();
break;
case "Option 2":
this.panelOption1.SendToBack();
this.panelOption3.SendToBack();
this.panelOption2.BringToFront();
this.panelOption2.Show();
this.panelOption3.Hide();
break;
case "Option 3":
this.panelOption2.Show();
this.panelOption2.SendToBack();
this.panelOption1.SendToBack();
this.panelOption3.BringToFront();
this.panelOption3.Show();
break;
default:
break;
}
<pre>
-- modified at 6:31 Friday 26th May, 2006
|
|
|
|
|
In Windows Form Designer generated code
you find the "panelOption3.Controls.Add(someControl);" etc.
Have you checked to see that your buttons in panelOption1 isn't also added to panelOption3?
Sounds like it since they show for both panels.
-Larantz-
|
|
|
|
|
Panel1 is added to the From
panel 2 is added to panel 1
panel 3 is added to panel 2
I checked and all controls that should be on panel1 are where they should be.
The same is true for controls of Panel2 & Panel3
|
|
|
|
|
Given this info the solution I posted will surely not work. I thought all panels were placed on the same container control. Is there any reason why you are placing within each other?
|
|
|
|