【问题标题】:Cannot implicitly convert type string to System.Windows.Forms.DataGridViewTextBoxColumn [duplicate]无法将类型字符串隐式转换为 System.Windows.Forms.DataGridViewTextBoxColumn [重复]
【发布时间】:2017-06-22 13:50:53
【问题描述】:

我为此尝试了以下解决方案,但仍然给我同样的错误: Cannot implicitly convert type 'string' to 'System.Windows.Forms.TextBox'

这是我的表单元素代码:

 private void InitializeComponent()
{
         this.Controls.Add(this.splitContainer1);
            this.ImeMode = System.Windows.Forms.ImeMode.On;
            this.Name = "UserForm"; // Here I have a problem while runing the application
            this.Text = "User Log Management";
}

我已尝试更改表单的名称,但仍然无法正常工作。

这里是 Snap 代码: 谢谢

【问题讨论】:

  • 您的表单上是否有一个TextBox 控件,您已调用Name?这是个坏主意!
  • 编译应用时默认采用
  • 是的,由于表单上的文本框控件仍然存在冲突。看我的回答。
  • 我刚刚意识到你链接的问题有完全相同的问题,你真的应该读过。

标签: c# asp.net windows


【解决方案1】:

表单中的一个文本框的 ID 为“名称”。将其重命名为“txtName”,您的代码应该可以正常工作

【讨论】:

  • 谢谢,它真的帮我找到了冲突。
【解决方案2】:

您的表单上有一个TextBox 控件,您已将其称为Name。这正在引起冲突。将您的文本框重命名为不同的名称。 WinForms 开发中的一个常见约定是使用控件前缀(或后缀)。例如 txt 用于文本框。例如txtName

有关命名的进一步讨论,请参阅here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-21
    • 1970-01-01
    • 2011-09-09
    • 2014-05-15
    • 2014-02-04
    • 2011-05-28
    相关资源
    最近更新 更多