Please Help me......
I want to Delete a row in RadGridView.
Here is my XMAL code
<my:RadGridView x:Name="gvEmpDet" ShowGroupPanel="False" AutoGenerateColumns="False" Width="400" RowEditEnded="gvEmpDet_RowEditEnded" BeginningEdit="gvEmpDet_BeginningEdit" SelectionChanged="gvEmpDet_SelectionChanged" RowStyle="{StaticResource GridViewRowStyle1}" >
<my:RadGridView.Columns>
<my:GridViewDataColumn Header="" >
<my:GridViewColumn.CellTemplate>
<DataTemplate>
<Button x:Name="btnDelete" Width="50" Height="22" Content="Delete" Click="btnDelete_Click" ></Button>
</DataTemplate>
</my:GridViewColumn.CellTemplate>
</my:GridViewDataColumn>
<my:GridViewDataColumn Header="Id" >
<my:GridViewDataColumn.CellTemplate>
<DataTemplate>
<HyperlinkButton x:Name="link" Content="{Binding EmpId}" Click="link_Click" ></HyperlinkButton>
</DataTemplate>
</my:GridViewDataColumn.CellTemplate>
</my:GridViewDataColumn>
<my:GridViewDataColumn Header="FirstName" DataMemberBinding="{Binding Path=FirstName}" ></my:GridViewDataColumn>
<my:GridViewDataColumn Header="LastName" DataMemberBinding="{Binding Path=LastName}"></my:GridViewDataColumn>
<my:GridViewDataColumn Header="Salary" DataMemberBinding="{Binding Path=Salary}" ></my:GridViewDataColumn>
<my:GridViewDataColumn Header="DepartmentId" DataMemberBinding="{Binding Path=DeptId}" ></my:GridViewDataColumn>
</my:RadGridView.Columns>
</my:RadGridView>
In My Gridview first columon i have place a Button and on Button click event i want to Delete that perticular Row.
Please find the attachment(screen1.png) for output of my Application.
Thanks in Advance.
16 Answers, 1 is accepted
Considering the attached picture I would suggest you to use commands as it is shown in our online demo.
Just add a RadButton in your DataTemplate as it is shown below:
<
telerik:RadButton
Content
=
"Delete"
Command
=
"telerikGrid:RadGridViewCommands.Delete"
CommandParameter
=
"{Binding}"
/>
Vanya Pavlova
the Telerik team
i follow your instructions to put a delete RadButton for a radGridView, like the demo shows. I have always a problem, the RedButton, in execution, is always disabled, and i can't enable it !! Every RadButton i use, which have defined the Command="Telerik....." is disabled by default. Can you help me?
The "Delete" button should be enabled by default. Have you configured the column similar to:
<
telerik:RadGridView
ItemsSource
=
"{Binding Clubs}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewColumn
>
<
telerik:GridViewColumn.CellTemplate
>
<
DataTemplate
>
<
telerik:RadButton
Content
=
"Delete"
Command
=
"telerikGrid:RadGridViewCommands.Delete"
CommandParameter
=
"{Binding}"
/>
</
DataTemplate
>
</
telerik:GridViewColumn.CellTemplate
>
</
telerik:GridViewColumn
>
....
</
telerik:RadGridView
>
If not, please share your implementation considering this column.
Regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
The config you posted is ok, but i don't want to put the button inside the grid, on every row, but i want to put it outside the radgridview, then in xaml file i wrote:
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
Margin="0,5,0,0">
<telerik:RadButton Width="150"
Content="Delete selected rows"
Margin="0,0,5,0"
Command="telerikGrid:RadGridViewCommands.Delete"
CommandTarget="{Binding ElementName=RadGridView1}" />
</StackPanel>
When i Execute the program the button is disabled. If i make a change to the grid, the button is still disabled. how can i do to enable it? i tried to write hard coded radbutton.isEnabled = true, but it is still disabled.
In the telerik demo of wpf ( commands example), i noted that if i try to edit a row, the delete button turns to disabled, and at the confirm of the editing, it return to be enabled. Is there a property of radgridview or radbutton that make this behavior? Maybe for this reason that my delete button is disabled??
The Button will be disabled until you select any rows (so that there are rows to be deleted). If you want to have a row innitially selected (by default), then you should set the IsSynchronizedWithCurrentItem property of the RadGridView to True. Does it help?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
i tried to set the IsSynchronizedWithCurrentItem property of the RadGridView to True, but the button is still disablet, either i select the rows manually with the click of mouse. I want to ask you if this problem is caused by my developement tool, i'm developing with Powerbuilder 12.5 .Net. Is it not compatible with this property? I feth the rows of a table in the database, add a row, and update, but i can't delete any row. With the button inside the grid i can delete the selected row, but the button outside the grid is disabled and so i don't know how to delete rows.
What is the result if you select a row, then press the "Delete" key?
I have also attached a test project (where I used your definition for the RadButton) that you can review.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
ps. Is there another way to delete a row from a gridview? I can't use classes because powerbuilder 12.5 .net doesn't declare classes. Any suggest? thank you...
I am not able to reproduce this behaviour on the test project (attached in my previous reply). Is it possible for you to change the solution and reproduce the issue? If I could reproduce the case, I would advise you better.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
<pbwpf:Window x:Class="w_wpf" x:ClassModifier="internal" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:pbwpf="clr-namespace:Sybase.PowerBuilder.WPF.Controls;assembly=Sybase.PowerBuilder.WPF.Controls" PBTitle="Window Title" PBHeight="3060" PBWidth="5243" MinBox="True" MaxBox="True" TitleBar="True" ControlMenu="True" Center="True" Resizable="True" Uid="5" Height="765" Width="1147" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">
<Grid Width="1032" Height="707">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="433*" />
<ColumnDefinition Width="488*" />
<ColumnDefinition Width="111*" />
</Grid.ColumnDefinitions>
<telerik:RadGridView HorizontalAlignment="Left" Name="radgridview1" TabIndex="10" VerticalAlignment="Top" Height="515" Width="921" pbwpf:Window.Skin="RoughGreen" AutoGenerateColumns="True" AlternateRowBackground="#FF5B21AD" ShowColumnFooters="True" ShowGroupFooters="True" Grid.ColumnSpan="2" IsSynchronizedWithCurrentItem="True">
<telerik:RadGridView.Columns>
<telerik:GridViewColumn Width="90">
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<telerik:RadButton Content="Delete"
Command="telerikGrid:RadGridViewCommands.Delete"
CommandParameter="{Binding}" />
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
<telerik:GridViewDataColumn Width="220">
<telerik:GridViewDataColumn.AggregateFunctions>
<telerik:CountFunction Caption="Count: " />
</telerik:GridViewDataColumn.AggregateFunctions>
</telerik:GridViewDataColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<telerik:RadButton Content="Retrieve" Grid.Column="2" Height="33" HorizontalAlignment="Left" Margin="37,12,0,0" Name="radbutton1" TabIndex="40" VerticalAlignment="Top" Width="74" />
<telerik:RadButton Content="Save" Grid.Column="2" Height="43" HorizontalAlignment="Left" Margin="37,51,0,0" Name="radbutton2" TabIndex="50" VerticalAlignment="Top" Width="74" />
<telerik:RadButton Content="Inserist row" Grid.Column="2" Height="40" HorizontalAlignment="Left" Margin="37,100,0,0" Name="radbutton4" TabIndex="70" VerticalAlignment="Top" Width="74" />
<telerik:RadButton Content="Delete " Command="telerikGrid:RadGridViewCommands.Delete" CommandTarget="{Binding ElementName=RadGridView1}" Grid.Column="2" Height="45" HorizontalAlignment="Left" Margin="37,345,0,0" Name="radbutton6" TabIndex="80" VerticalAlignment="Top" Width="56" />
</Grid>
</pbwpf:Window>
The only disabled button is the "Delete" outside the grid. To bind the gridview to a db i use the RadGridView.ItemsSource command equals to a datatable.DefaultView
Thank you.
Your RadGridView is named: Name="radgridview1". Then you reference it with a different Name: CommandTarget="{Binding ElementName=RadGridView1}"
Please use the same Name and let me know about the result.
All the best,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
thanks a lot!! You're great, i used the right name and now all the buttons in the grid work fine!
Thank you!
asp .net rad controls using for grid directly not deleted
after add new two template columns
in grid
after next one coding in vb.net
Dim lngPrdId As Long means u r table id
Dim rowIndex As Integer means this is one variable for asp using vb
Try
Dim btn As RadButton = DirectCast(sender, RadButton)
Dim dataitem As GridDataItem = DirectCast(btn.NamingContainer, GridDataItem)
rowIndex = dataitem.ItemIndex
With rgvDisplay
lngPrdId = Val(.Items(rowIndex).Cells(3).Text)
End With
If lngPrdId = 0 Then Exit Sub means u r table id
If cn.State = 1 Then cn.Close()
cn.Open()
ExecNonQry("Delete from Project where numProjectId=" & lngPrdId & "", cn)
RadAjaxManager1.Alert("Successfully Deleted..")
Call prcDisplay()
Call prcClearCntrls()
Catch ex As Exception
RadAjaxManager1.Alert(ex.Message.ToString)
End Try
Am having problem here, the delete button is not enabling
Thanks in advance
Would you please open a new support thread and attach a demo project illustrating the issue you have met? That way I will check it locally and advise further.
Regards,
Didie
Telerik