Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# I'm using Visual Studio and i got a error "cs0029" but don't know what it is.

audric

New Coder
C#:
namespace AppZero
{
    partial class Form1
    {
        /// <summary>
        ///  Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        ///  Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private EventHandler GetClick()
        {
            return button1; // erro is here says " cs0029 not possible to convert System.windows.forms.button to system.eventhandler
        }

        private Button GetButton1()
        {
            return button1;
        }

        #region Windows Form Designer generated code

        /// <summary>
        ///  Required method for Designer support - do not modify
        ///  the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent(EventHandler click, Button button1)
        {
            dgv = new DataGridView();
            Column1 = new DataGridViewTextBoxColumn();
            Column2 = new DataGridViewTextBoxColumn();
            Column3 = new DataGridViewTextBoxColumn();
            Column4 = new DataGridViewTextBoxColumn();
            Column5 = new DataGridViewTextBoxColumn();
            Column6 = new DataGridViewTextBoxColumn();
            Column7 = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
            dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
            button1 = new Button();
            openFileDialog1 = new OpenFileDialog();
            ((System.ComponentModel.ISupportInitialize)dgv).BeginInit();
            SuspendLayout();
            //
            // dgv
            //
            dgv.AllowUserToAddRows = false;
            dgv.BackgroundColor = Color.White;
            dgv.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            dgv.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3, Column4, Column5, Column6, Column7, dataGridViewTextBoxColumn1, dataGridViewTextBoxColumn2 });
            dgv.Location = new Point(22, 104);
            dgv.Name = "dgv";
            dgv.RowHeadersVisible = false;
            dgv.RowTemplate.Height = 25;
            dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgv.Size = new Size(873, 334);
            dgv.TabIndex = 0;
            dgv.CellContentClick += dataGridView1_CellContentClick;
            //
            // Column1
            //
            Column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            Column1.HeaderText = "Linha 1";
            Column1.Name = "Column1";
            Column1.Width = 70;
            //
            // Column2
            //
            Column2.HeaderText = "Linha 2";
            Column2.Name = "Column2";
            //
            // Column3
            //
            Column3.HeaderText = "Linha 3";
            Column3.Name = "Column3";
            //
            // Column4
            //
            Column4.HeaderText = "Linha 4";
            Column4.Name = "Column4";
            //
            // Column5
            //
            Column5.HeaderText = "Linha 5";
            Column5.Name = "Column5";
            //
            // Column6
            //
            Column6.HeaderText = "Linha 6";
            Column6.Name = "Column6";
            //
            // Column7
            //
            Column7.HeaderText = "Linha 7";
            Column7.Name = "Column7";
            //
            // dataGridViewTextBoxColumn1
            //
            dataGridViewTextBoxColumn1.HeaderText = "Linha 8";
            dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
            //
            // dataGridViewTextBoxColumn2
            //
            dataGridViewTextBoxColumn2.HeaderText = "Linha 8";
            dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
            //
            // button1
            //
            button1.Location = new Point(22, 53);
            button1.Name = "button1";
            button1.Size = new Size(136, 45);
            button1.TabIndex = 1;
            button1.Text = "Ler Ficheiros";
            button1.UseVisualStyleBackColor = true;
  //          click += button1;
            //
            // openFileDialog1
            //
            openFileDialog1.FileName = "openFD";
            //
            // Form1
            //
            AutoScaleDimensions = new SizeF(7F, 15F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(927, 450);
            Controls.Add(button1);
            Controls.Add(dgv);
            Name = "Form1";
            Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)dgv).EndInit();
            ResumeLayout(false);
        }

        #endregion

        private DataGridView dgv;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private DataGridViewTextBoxColumn Column4;
        private DataGridViewTextBoxColumn Column5;
        private DataGridViewTextBoxColumn Column6;
        private DataGridViewTextBoxColumn Column7;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
        private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
#pragma warning disable CS0649 // Campo "Form1.button1" nunca é atribuído e sempre terá seu valor padrão null
        private Button button1;
#pragma warning restore CS0649 // Campo "Form1.button1" nunca é atribuído e sempre terá seu valor padrão null
        private OpenFileDialog openFileDialog1;
    }
}
 
Hi there,

Can you provide a little more information? e.g. what have you tried, where are you seeing this error, what is your intended outcome etc

Compiler Error CS0029 generally refers to when you're trying to convert type 'type' to 'type'. More info can be found on Microsofts website here, I don't have much experience with this error so hopefully someone can explain in more detail.
 
It should be obvious that a function of type EventHandler cannot return a button. The error message makes that perfectly clear. What do you want with that function GetClick() anyway ? It's not even being used. And you already have a function that returns button1.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom