Maher Khalil
Top achievements
Rank 1
Maher Khalil
asked on 24 May 2010, 09:03 AM
Hi
I'm trying to add a button column to the grid i didn't find button in the grid columns after search i found this article
http://www.telerik.com/help/winforms/grid_gridviewcommandcolumn.html
i used the code supplied but the column always show as TextBox and not running the the radGridView1_CommandCellClick event
the button has fixed text(search) that open search Dialog then the selected data from the dialog will be written in the grid row that fires the button click could you please provide some code for adding the the button
thank you
I'm trying to add a button column to the grid i didn't find button in the grid columns after search i found this article
http://www.telerik.com/help/winforms/grid_gridviewcommandcolumn.html
i used the code supplied but the column always show as TextBox and not running the the radGridView1_CommandCellClick event
the button has fixed text(search) that open search Dialog then the selected data from the dialog will be written in the grid row that fires the button click could you please provide some code for adding the the button
thank you
3 Answers, 1 is accepted
0
Hi Maher Khalil,
Thank you for contacting us.
To achieve your task you need to add a GridViewCommandColumn to the RadGridView:
Then you need to handle the CommandCellClick event, so you can show the search dialog you need and update the RadGridView row:
I hope it helps. Please write back if you have further questions.
Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Thank you for contacting us.
To achieve your task you need to add a GridViewCommandColumn to the RadGridView:
GridViewCommandColumn commandColumn =
new
GridViewCommandColumn(
"Search"
);
commandColumn.UseDefaultText =
true
;
commandColumn.DefaultText =
"Search"
;
this
.radGridView1.Columns.Add(commandColumn);
Then you need to handle the CommandCellClick event, so you can show the search dialog you need and update the RadGridView row:
void
radGridView1_CommandCellClick(
object
sender, EventArgs e)
{
OpenFileDialog dialog =
new
OpenFileDialog();
DialogResult result = dialog.ShowDialog();
if
(result == DialogResult.OK)
{
string
selectedFileName = dialog.FileName;
this
.radGridView1.CurrentRow.Cells[0].Value = selectedFileName;
}
}
I hope it helps. Please write back if you have further questions.
Greetings,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Cristiana
Top achievements
Rank 1
answered on 10 Jul 2014, 09:49 PM
Good afternoon,
in my project I have a button inside a gridvew that clicking opens a form.
This form is what I fill in two columns of the grid.
wanted to know how I program the button to open the form.
My code:
//Preenche template registos
templateRegistar.AllowAddNewRow = false;
templateRegistar.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
templateRegistar.Caption = "Registo de Lavagem de Fardamento";
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "NÂș Ticket", FieldName =
"SYS_Registo_Entrega.SYS_Ticket.Ticket_ID", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Fardamento", FieldName =
"Fardamento_Funcionario.Fardamento.Descricao", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Quantidade", FieldName = "Quantidade", IsVisible = true
});
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Utilizador", FieldName =
"SYS_Utilizador.Funcionario.Nome_Funcionario", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Data Entrega", FieldName = "DtEntrega", IsVisible = true
});
templateRegistar.Columns.Add(new GridViewComboBoxColumn {
HeaderText = "Utilizador", FieldName = "Utilizador_IDLevantamento",
IsVisible = true });
templateRegistar.Columns.Add(new GridViewComboBoxColumn {
HeaderText = "Data Levantamento", FieldName = "DtLevantamento",
IsVisible = true });
templateRegistar.Columns.Add(new GridViewCommandColumn {
HeaderText = "", DefaultText = "Registar Levantamento", UseDefaultText =
true, MaxWidth = 150, Name = "Levantamento" });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Num_Mecanografico_Funcionario", FieldName =
"Num_Mecanografico_Funcionario", IsVisible = false });
GridViewRelation relationRegistar = new GridViewRelation(radGridViewFuncionarios.MasterTemplate);
relationRegistar.ChildTemplate = templateRegistar;
relationRegistar.RelationName = "FuncionarioLavagem";
relationRegistar.ParentColumnNames.Add("Num_Mecanografico_Funcionario");
relationRegistar.ChildColumnNames.Add("Num_Mecanografico_Funcionario");
radGridViewFuncionarios.Relations.Add(relationRegistar);
radGridViewFuncionarios.CommandCellClick += radGridViewFuncionarios_CommandCellClick;
//Botao registar Levantamento
void radGridViewFuncionarios_CommandCellClick1(object sender, EventArgs e)
{
GridCommandCellElement click = (GridCommandCellElement)sender;
SYS_Registo_Entrega row = click.RowInfo.DataBoundItem as SYS_Registo_Entrega;
RegistarLevantamento reg = new RegistarLevantamento(row);
if (reg.ShowDialog() == DialogResult.OK)
{
PreencheFuncionarios(); // se foi adicionado novo funcionario a BD, entao atualiza a lista
}
}
in my project I have a button inside a gridvew that clicking opens a form.
This form is what I fill in two columns of the grid.
wanted to know how I program the button to open the form.
My code:
//Preenche template registos
templateRegistar.AllowAddNewRow = false;
templateRegistar.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
templateRegistar.Caption = "Registo de Lavagem de Fardamento";
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "NÂș Ticket", FieldName =
"SYS_Registo_Entrega.SYS_Ticket.Ticket_ID", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Fardamento", FieldName =
"Fardamento_Funcionario.Fardamento.Descricao", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Quantidade", FieldName = "Quantidade", IsVisible = true
});
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Utilizador", FieldName =
"SYS_Utilizador.Funcionario.Nome_Funcionario", IsVisible = true });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Data Entrega", FieldName = "DtEntrega", IsVisible = true
});
templateRegistar.Columns.Add(new GridViewComboBoxColumn {
HeaderText = "Utilizador", FieldName = "Utilizador_IDLevantamento",
IsVisible = true });
templateRegistar.Columns.Add(new GridViewComboBoxColumn {
HeaderText = "Data Levantamento", FieldName = "DtLevantamento",
IsVisible = true });
templateRegistar.Columns.Add(new GridViewCommandColumn {
HeaderText = "", DefaultText = "Registar Levantamento", UseDefaultText =
true, MaxWidth = 150, Name = "Levantamento" });
templateRegistar.Columns.Add(new GridViewTextBoxColumn {
HeaderText = "Num_Mecanografico_Funcionario", FieldName =
"Num_Mecanografico_Funcionario", IsVisible = false });
GridViewRelation relationRegistar = new GridViewRelation(radGridViewFuncionarios.MasterTemplate);
relationRegistar.ChildTemplate = templateRegistar;
relationRegistar.RelationName = "FuncionarioLavagem";
relationRegistar.ParentColumnNames.Add("Num_Mecanografico_Funcionario");
relationRegistar.ChildColumnNames.Add("Num_Mecanografico_Funcionario");
radGridViewFuncionarios.Relations.Add(relationRegistar);
radGridViewFuncionarios.CommandCellClick += radGridViewFuncionarios_CommandCellClick;
//Botao registar Levantamento
void radGridViewFuncionarios_CommandCellClick1(object sender, EventArgs e)
{
GridCommandCellElement click = (GridCommandCellElement)sender;
SYS_Registo_Entrega row = click.RowInfo.DataBoundItem as SYS_Registo_Entrega;
RegistarLevantamento reg = new RegistarLevantamento(row);
if (reg.ShowDialog() == DialogResult.OK)
{
PreencheFuncionarios(); // se foi adicionado novo funcionario a BD, entao atualiza a lista
}
}
0
Hello Cristiana,
Thank you for writing.
According to the provided code snippet, it seems that you use hierarchical RadGridView with GridViewCommandColumn in the child template. As you have already found out, the CommandCellClick event is the appropriate event to detect clicking over the command cell. In the event handler you can open another form, using the ShowDialog method. In the form's constructor you can pass the clicked data bound object and visualize it in the new form in order to perform some changes for example. Please find attached a sample project, demonstrating this behavior. I am not sure if it is the exact requirement. If it is not, please specify in details what is specific case. It would be better if you open a new thread and provide a sample project with the very specific case. Thank you in advance.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Thank you for writing.
According to the provided code snippet, it seems that you use hierarchical RadGridView with GridViewCommandColumn in the child template. As you have already found out, the CommandCellClick event is the appropriate event to detect clicking over the command cell. In the event handler you can open another form, using the ShowDialog method. In the form's constructor you can pass the clicked data bound object and visualize it in the new form in order to perform some changes for example. Please find attached a sample project, demonstrating this behavior. I am not sure if it is the exact requirement. If it is not, please specify in details what is specific case. It would be better if you open a new thread and provide a sample project with the very specific case. Thank you in advance.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.