Estoy intentando hacer una suma como la de excel (automática) en C#, pero el código hace que un numero digitado se sume por si mismo 10 veces (mostrado en el total), para solucionarlo intente dividir el resultado entre 10, pero tampoco podía ya que me decía que no se puede convertir un "float a un string".
Código:
wsNumeric20.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch {}
};
wsNumeric19.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric18.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric17.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric16.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric15.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric14.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric13.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric12.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
wsNumeric11.EditValueChanged += (s, e) =>
{
try
{
wsNumeric21.Text =
(float.Parse(wsNumeric20.Text) +
float.Parse(wsNumeric19.Text) +
float.Parse(wsNumeric18.Text) +
float.Parse(wsNumeric17.Text) +
float.Parse(wsNumeric16.Text) +
float.Parse(wsNumeric15.Text) +
float.Parse(wsNumeric14.Text) +
float.Parse(wsNumeric13.Text) +
float.Parse(wsNumeric12.Text) +
float.Parse(wsNumeric11.Text).ToString());
}
catch { }
};
Pero al momento de ejecutarse ocurre esto (Ver imagen).
(PD: el 5 * el 2000 quiero que se sumen todas las multiplicaciones), se que fácilmente puedo hacerlo agregando un botón y etc... pero lo quiero hacer sin botones ni eventos: