我试图通过检查用户在我的DataGridViewCell中输入的大小是否超过允许的最大值来保护用户免受错误消息的影响。
我做的是:
private void dataGridView3_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    if (e.ColumnIndex == 1)
    {
        string selected = (dataGridView3[e.RowIndex, 1] as DataGridViewTextBoxCell).FormattedValue.ToString();
        if (selected.Length > 50)
        {
            dataGridView3[e.RowIndex, 1].Value = selected.Take(50).ToString();
        }
    }
}选中的是我的文本,但我在更新时收到错误信息:无法将字符串转换为int32...如果我使用=0,那就没有意义了。这是怎么回事?
当我更新长度大于50的文本框时出错,它说我的值不是整数。但它必须是一个字符串。我刚从同一个单元格读取了一个字符串。
发布于 2011-05-03 18:56:18
您必须将字符串转换为正确的Integer值。您正在尝试使用字符串设置Integer值,但它无法执行转换。
https://stackoverflow.com/questions/5868360
复制相似问题