您好,我是C#的初学者,已经编写了一个程序。这是代码:
视觉工作室...
这是一个乘法表生成器。我注意到,为列表框添加太多行使程序挂起。有人告诉我,我可以使用数据网格视图来解决该问题。但是,由于我是初学者,因此需要一些帮助。我已经搜索了Internet,但是它们都是有关如何将SQL数据添加到数据网格视图的代码。
任何帮助将不胜感激
C#:
using System;using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double of = 0;
double from = 0;
double to = 0;
double ans = 0;
Table.Items.Clear();
if (double.TryParse(Of.Text, out of) && double.TryParse(From.Text, out from) && double.TryParse(To.Text, out to))
{
for (double i = from; i <= to; i++)
{
ans = i * of;
Table.Items.Add(of + " x " + i + " = " + ans.ToString());
}
}
else
{
MessageBox.Show("Please enter a valid value");
}
}
这是一个乘法表生成器。我注意到,为列表框添加太多行使程序挂起。有人告诉我,我可以使用数据网格视图来解决该问题。但是,由于我是初学者,因此需要一些帮助。我已经搜索了Internet,但是它们都是有关如何将SQL数据添加到数据网格视图的代码。
任何帮助将不胜感激