This is a migrated thread and some comments may be shown as answers.

How to Delete a Row in RadGridView

16 Answers 456 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
RamKalyan
Top achievements
Rank 1
RamKalyan asked on 09 Dec 2010, 08:38 AM
Hi All,
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

Sort by
0
Vanya Pavlova
Telerik team
answered on 09 Dec 2010, 10:00 AM
Hello RamKalyan,

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}" />
 

Best wishes,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Angelo
Top achievements
Rank 1
answered on 20 Feb 2013, 10:42 AM
Hello Vanya Pavlova,
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?
0
Dimitrina
Telerik team
answered on 20 Feb 2013, 11:48 AM
Hello,

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.

0
Angelo
Top achievements
Rank 1
answered on 20 Feb 2013, 03:49 PM
Thank you for the answer,
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??
0
Dimitrina
Telerik team
answered on 20 Feb 2013, 03:56 PM
Hello,

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?
 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Angelo
Top achievements
Rank 1
answered on 20 Feb 2013, 04:11 PM
Hi,
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.
0
Dimitrina
Telerik team
answered on 20 Feb 2013, 04:19 PM
Hello,

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.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Angelo
Top achievements
Rank 1
answered on 20 Feb 2013, 04:29 PM
With the config i posted, when i select a row, the "delete" button is disabled and so no changes made to the grid. With the config about the button inside the grid, i can delete the selected row, but in my project i need the button outside the grid. I notes that if i don't declare Command="telerikGrid:RadGridViewCommands.Delete" in the xaml file, in running the button is enabled. When i redeclare the Command = "...." it turns to be disabled...
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...
0
Dimitrina
Telerik team
answered on 20 Feb 2013, 04:54 PM
Hello,

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.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Angelo
Top achievements
Rank 1
answered on 20 Feb 2013, 05:02 PM
Here's my xaml file:

<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.
0
Angelo
Top achievements
Rank 1
answered on 20 Feb 2013, 05:36 PM
This is a screenshot. The disabled button is "Cancella" button.
0
Dimitrina
Telerik team
answered on 21 Feb 2013, 09:24 AM
Hello,

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.

0
Angelo
Top achievements
Rank 1
answered on 21 Feb 2013, 10:43 AM
Hello,
thanks a lot!! You're great, i used the right name and now all the buttons in the grid work fine!
Thank you!
0
Siva
Top achievements
Rank 1
answered on 04 Nov 2013, 11:59 AM
  hello this is delete grid in row 
  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
0
Bindu
Top achievements
Rank 1
answered on 05 Sep 2014, 06:57 AM
Hello,

Am having problem here, the delete button is not enabling

Thanks in advance
0
Dimitrina
Telerik team
answered on 08 Sep 2014, 08:12 AM
Hello,

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
 
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.
 
Tags
General Discussions
Asked by
RamKalyan
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Angelo
Top achievements
Rank 1
Dimitrina
Telerik team
Siva
Top achievements
Rank 1
Bindu
Top achievements
Rank 1
Share this question
or