DataGridView Custom Column Control Events
-
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.
-
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.
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:
-
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 have to include the custom contorl in DataGridViewColumn, not the control it self.
sorry for my bad English.
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:
-
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:
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.
-
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.
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 calledRaiseCellClick()
,RaiseCellContentClick()
, among other methods to raise the eventsDatagridView.CellClick
event, andDataGridView.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: -
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 calledRaiseCellClick()
,RaiseCellContentClick()
, among other methods to raise the eventsDatagridView.CellClick
event, andDataGridView.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: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. Thanxsorry for my bad English.
-
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. Thanxsorry for my bad English.
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 likeMyCustomColumn.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: