How to Delete a Row in RadGridView

17 posts, 0 answers
  1. RamKalyan
    RamKalyan avatar
    5 posts
    Member since:
    Aug 2009

    Posted 09 Dec 2010 Link to this post

    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.




               

  2. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 09 Dec 2010 Link to this post

    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
  3. DevCraft banner
  4. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 20 Feb 2013 Link to this post

    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?
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 20 Feb 2013 Link to this post

    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.

  6. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 20 Feb 2013 Link to this post

    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??
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 20 Feb 2013 Link to this post

    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.

  8. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 20 Feb 2013 Link to this post

    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.
  9. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 20 Feb 2013 Link to this post

    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.

  10. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 20 Feb 2013 Link to this post

    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...
  11. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 20 Feb 2013 Link to this post

    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.

  12. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 20 Feb 2013 Link to this post

    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.
  13. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 20 Feb 2013 Link to this post

    This is a screenshot. The disabled button is "Cancella" button.
  14. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 Feb 2013 Link to this post

    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.

  15. Angelo
    Angelo avatar
    7 posts
    Member since:
    Feb 2013

    Posted 21 Feb 2013 Link to this post

    Hello,
    thanks a lot!! You're great, i used the right name and now all the buttons in the grid work fine!
    Thank you!
  16. Siva
    Siva avatar
    1 posts
    Member since:
    Nov 2013

    Posted 04 Nov 2013 Link to this post

      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
  17. Bindu
    Bindu avatar
    25 posts
    Member since:
    Aug 2014

    Posted 05 Sep 2014 in reply to Dimitrina Link to this post

    Hello,

    Am having problem here, the delete button is not enabling

    Thanks in advance
  18. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Sep 2014 Link to this post

    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.
     
Back to Top
DevCraft banner