行数添加到标签,标签数加1

时间:2019-05-15 16:33:16

标签: c# datagridview count

我正在尝试创建要添加到Datagridview的唯一ID(在网格上关闭了添加),因此我在填充数据时对行进行计数。我有一个显示计数的标签。我要执行的操作是说计数是“ 75”,然后单击“新建”,然后计数变为“ 76”,但我知道这有点愚蠢又简单。

基本上,这是一个用于库存的程序,可以在线运行MySQL(phpMyAdmin)服务器并与Windows应用程序进行通讯。

// Read in the value again.
int count = ++_x;
//Get Count and Add 1 (74 to 75 to 76 etc..
lblCount.Text = dataGridView1.Rows.Count.ToString() + (_x.ToString());
//Update the ID from lblCount Text
txtID.Text = lblCount.Text;

从lblCount标签中的任何数字中加1。

1 个答案:

答案 0 :(得分:0)

尝试一下:

private int _lastCount;

public void MyProc()
{
    //Get Count and Add 1 (74 to 75 to 76 etc..
    int count = _lastCount + 1;
    lblCount.Text = count.ToString();

    //Update the ID 
    txtID.Text = count.ToString();

    _lastCount = count;
}

否则,您要将两个字符串加在一起,并且对字符串的添加操作会将它们串联起来。

相关问题