|
Hi everybody!
I have a DataGridView which has a column of type double. When the user types something bad(not a number) i want to set back the cell value on the previous value of the cell(the value which was before the user edited the cell) or just set a default value.
I try to parse the value in the CellValidating event and if the parse fails then i set a default value but it doesn't works. I think because the cell still remains in editing mode.
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
double newDouble;
if (e.ColumnIndex == 5)
{
if (!double.TryParse(e.FormattedValue.ToString(), out newDouble))
{
MessageBox.Show("Error parsing the data!");
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0.0;
}
}
}
How can i correct this?
Thanks!
|
|
|
|
|
you have e.ColumnIndex and e.RowIndex , so access the cell directly through them
SkyWalker
|
|
|
|
|
Hi!
I did this. You can see it on the code which i posted in the question but it does't work.
Anything else?
|
|
|
|
|
|
I have this code but I need to convert to an array. So this sum program should be in array.
Could someone help me out.
static void Main(string[] args)
{
string firstNumber, // first string entered by user
secondNumber,
thirdNumber;
// second string entered by user
int number1, // first number to add
number2,// second number to add
number3,//third number to add
sum; // sum of number1, number2, and number3
// prompt for and read first number from user as string
Console.Write( "Please enter the first integer: " );
firstNumber = Console.ReadLine();
// read second number from user as string
Console.Write( "\nPlease enter the second integer: " );
secondNumber = Console.ReadLine();
Console.Write("\nPlease enter the third integer: ");
thirdNumber = Console.ReadLine();
// convert numbers from type string to type int. Note: "int" would have worked as well.
number1 = Int32.Parse( firstNumber );
number2 = Int32.Parse( secondNumber );
number3 = Int32.Parse( thirdNumber );
// add numbers
sum = number1 + number2 + number3;
// display results
Console.WriteLine("\nThe sum is {0}.", sum);
}
}
}
|
|
|
|
|
Here we go, changed it all to work with arrays.
<br />
static void Main(string[] args)<br />
{<br />
int[] Numbers = new int[3];<br />
int[] sum = new int[1];<br />
<br />
Console.Write("Please enter the first integer: ");<br />
Numbers[0] = Convert.ToInt16(Console.ReadLine());<br />
<br />
Console.Write("\nPlease enter the second integer: ");<br />
Numbers[1] = Convert.ToInt16(Console.ReadLine());<br />
<br />
Console.Write("\nPlease enter the third integer: ");<br />
Numbers[2] = Convert.ToInt16(Console.ReadLine());<br />
<br />
for (int i = 0; i < Numbers.Length; i++)<br />
sum[0] += Numbers[i];<br />
<br />
Console.WriteLine("\nThe sum is {0}.", sum[0]);<br />
<br />
Console.ReadKey();<br />
}<br />
|
|
|
|
|
ProdigiSA,
You just did someones homework for them
Regards,
Gareth.
|
|
|
|
|
Wewps
|
|
|
|
|
How do you find an average of three numbers .
|
|
|
|
|
|
I'm only in 8th grade and I'm learning C# by myself. So shut up if you do not know.
|
|
|
|
|
Better u can use arraylist and solve this issue.
otherwise u can define the int array and size.
Continue...
|
|
|
|
|
Pfft... recursion is the way to go here. All classroom assignments require recursion.
|
|
|
|
|
Hi,
This is my interface
DataTable FindAll();<br />
implementation is
<br />
public DataTable FindAll()<br />
{ String query = "SELECT * FROM Media";<br />
DataTable dt = util.DatabaseManager.ExecuteQuery(ConnectionString, query, "outdoordata");<br />
if (dt.Rows.Count == 0)<br />
{<br />
return null;<br />
}<br />
return new media(dt.rows[0]);------it is showing error "cannot implicitly convert media to system.data.datatable.<br />
}<br /> Here is media is class which done the following
<br />
public class media<br />
{<br />
public Media(DataRow dr)<br />
{<br />
if (dr["media_type_id"] != DBNull.Value)<br />
{<br />
this.media_type_id = Int32.Parse(dr["media_type_id"].ToString());<br />
}<br />
if (dr["description"] != DBNull.Value)<br />
{<br />
this.description = dr["description"].ToString();<br />
}<br />
if (dr["width"] != DBNull.Value)<br />
{<br />
this.width = Double.Parse(dr["width"].ToString());<br />
}<br />
<br />
}<br /> It is giving error is "cannot implicitly convert media to system.data.datable
murali krishna
|
|
|
|
|
Your function's signature is DataTable FindAll() , therefore it should return a DataTable object and not a Media one
Change the return type to Media .
SkyWalker
|
|
|
|
|
Hi I am using firebird database using C#.Net.I am unable to connect firebird db windows application and windows service, at a time only one application is working with fire bird db.
Please help me how to connect firebird db from two applicatins like windows application(Desk Top)and windows service.
|
|
|
|
|
Hello,
I am using listview to add, delete and update items. Updation is done every 100ms and there is a lot of flickering. I used BeginUpdate() and Endupdate() while removing and inserting new row. The flickering reduces when the application is run on Windows 2000 but not on Windows XP, Any idea?
Thanks,
Sushma
|
|
|
|
|
YourControl.SuspendLayout()
... do something ...
YourControl.ResumeLayout()
SkyWalker
|
|
|
|
|
Thanks... I tried it out but there was no difference in flickering
|
|
|
|
|
If this is a windows form, then you may need to set the form for double buffering. A search here or on the web will show you how.
|
|
|
|
|
|
Your C# program is going to try and access the fortran code via COM. So your Fortran code has to expose the COM interface in order for C# to properly communicate with it.
|
|
|
|
|
thanks for your reply, your advice may be a pretty good solution, but for me that's a little tough, I have no idea of Com.Anyway, thanks a lot.
|
|
|
|
|
Is the FORTRAN program developed within the .NET environment?
If not, how is the FORTRAN written? That tool may have an option to expose the FORTRAN to COM aS part of the build process.
|
|
|
|
|
hi friend im using vs2005.how can i add AjaxContolToolkit to my web application?
Hi,Im Razana
|
|
|
|