Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataGridView Custom Column Control Events

DataGridView Custom Column Control Events

Scheduled Pinned Locked Moved C#
helptutorialquestion
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Itanium
    wrote on last edited by
    #1

    I have created a custom datagridviewColumn control containig a TextBox+Button. I want to access the events of these controls directly, for example TextBox_textChanged, Button_MouseHover. following code has been written for this, but it is not working :confused: DXDataGridViewTextBoxButtonColumn btn = new DXDataGridViewTextBoxButtonColumn(); ((DXTextBoxButtonCell)btn.CellTemplate).SSTextBoxButton.Button.Click += new EventHandler(SSTextBoxButton_Enter); ((DXTextBoxButtonCell)btn.CellTemplate).SSTextBoxButton.Enter += new EventHandler(SSTextBoxButton_Enter); I have simply shown a messagebox in its event handler. Can anyone help?

    sorry for my bad English.

    N 1 Reply Last reply
    0
    • I Itanium

      I have created a custom datagridviewColumn control containig a TextBox+Button. I want to access the events of these controls directly, for example TextBox_textChanged, Button_MouseHover. following code has been written for this, but it is not working :confused: DXDataGridViewTextBoxButtonColumn btn = new DXDataGridViewTextBoxButtonColumn(); ((DXTextBoxButtonCell)btn.CellTemplate).SSTextBoxButton.Button.Click += new EventHandler(SSTextBoxButton_Enter); ((DXTextBoxButtonCell)btn.CellTemplate).SSTextBoxButton.Enter += new EventHandler(SSTextBoxButton_Enter); I have simply shown a messagebox in its event handler. Can anyone help?

      sorry for my bad English.

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello

      MyCustomControl control = new MyCustomControl(); //Includes a public member of type Button called MyButton
      control.MyButton.Click += new EventHandler(MyHandler);

      What's wrong with simplicity??!! Regards:rose:

      I 1 Reply Last reply
      0
      • N Nader Elshehabi

        Hello

        MyCustomControl control = new MyCustomControl(); //Includes a public member of type Button called MyButton
        control.MyButton.Click += new EventHandler(MyHandler);

        What's wrong with simplicity??!! Regards:rose:

        I Offline
        I Offline
        Itanium
        wrote on last edited by
        #3

        I have to include the custom contorl in DataGridViewColumn, not the control it self.

        sorry for my bad English.

        N 1 Reply Last reply
        0
        • I Itanium

          I have to include the custom contorl in DataGridViewColumn, not the control it self.

          sorry for my bad English.

          N Offline
          N Offline
          Nader Elshehabi
          wrote on last edited by
          #4

          Hello Let me get this right!! Your problem is that you made a custom control - TextBox & a Button-, and you want to display it in the header cell?? Or is it in all cells of the column?? Regards:rose:

          I 1 Reply Last reply
          0
          • N Nader Elshehabi

            Hello Let me get this right!! Your problem is that you made a custom control - TextBox & a Button-, and you want to display it in the header cell?? Or is it in all cells of the column?? Regards:rose:

            I Offline
            I Offline
            Itanium
            wrote on last edited by
            #5

            Hello, Infact i want to display it in all cells. I have been succeded in doing that, Now i want to handle the event of that control. I have writeen the code in my first post. I dont know that y these events do not get triggered. :confused: Let me make it simple, forget about custom control. say i want to handle the events of button in DataGridViewButtonColumn, tell me how i will do that? Thanx

            sorry for my bad English.

            N 1 Reply Last reply
            0
            • I Itanium

              Hello, Infact i want to display it in all cells. I have been succeded in doing that, Now i want to handle the event of that control. I have writeen the code in my first post. I dont know that y these events do not get triggered. :confused: Let me make it simple, forget about custom control. say i want to handle the events of button in DataGridViewButtonColumn, tell me how i will do that? Thanx

              sorry for my bad English.

              N Offline
              N Offline
              Nader Elshehabi
              wrote on last edited by
              #6

              Hello Now I got your problem... Actually custom DatagridView columns are inherited -after some fathers- from DataGridViewElemnt. In that class you will find protected methods called RaiseCellClick(), RaiseCellContentClick(), among other methods to raise the events DatagridView.CellClick event, and DataGridView.CellContentClick. So the control that will handle the events is the DataGridView actually by the above events. If your custom control doesn't fire these events automatically -I don't know how you implemented them!-, so when you see suitable fire them yourself using the Raise methods. Regards:rose:

              I 1 Reply Last reply
              0
              • N Nader Elshehabi

                Hello Now I got your problem... Actually custom DatagridView columns are inherited -after some fathers- from DataGridViewElemnt. In that class you will find protected methods called RaiseCellClick(), RaiseCellContentClick(), among other methods to raise the events DatagridView.CellClick event, and DataGridView.CellContentClick. So the control that will handle the events is the DataGridView actually by the above events. If your custom control doesn't fire these events automatically -I don't know how you implemented them!-, so when you see suitable fire them yourself using the Raise methods. Regards:rose:

                I Offline
                I Offline
                Itanium
                wrote on last edited by
                #7

                Thanx Nader for your help public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { ase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); DXTextBoxButtonColumnEditingControl **ctl** = DataGridView.EditingControl as DXTextBoxButtonColumnEditingControl; if(ctl !=null) if (this.Value != null) ctl.SSTextBox.Text = (string)this.Value; else ctl.SSTextBox.Text = string.Empty; } i want this ctl to be accessed in the form where datagridcolumn will be used. Thanx

                sorry for my bad English.

                N 1 Reply Last reply
                0
                • I Itanium

                  Thanx Nader for your help public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle) { ase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle); DXTextBoxButtonColumnEditingControl **ctl** = DataGridView.EditingControl as DXTextBoxButtonColumnEditingControl; if(ctl !=null) if (this.Value != null) ctl.SSTextBox.Text = (string)this.Value; else ctl.SSTextBox.Text = string.Empty; } i want this ctl to be accessed in the form where datagridcolumn will be used. Thanx

                  sorry for my bad English.

                  N Offline
                  N Offline
                  Nader Elshehabi
                  wrote on last edited by
                  #8

                  Hello I'm sorry my reply came very late, but your email notification arrived to my just now!! You can't acess ctl this way because you've declared it as a local variable in a method. Declare it as a public member in your class, and access it like MyCustomColumn.ctl.Click for the click event as an example. I don't know if my reply would help you or it came too late, but forgive me.

                  Regards:rose:

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups