How to add New Row to the Teleric Grid upon click on a button in a previous row.

4 posts, 1 answers
  1. Nipuna
    Nipuna avatar
    2 posts
    Member since:
    Jul 2015

    Posted 13 Jul 2015 Link to this post

    'Could anybody plesae tell me , how can I add a new row to this table using VB code ?
      
    'dgPeripherals.AllowAddNewRow = True
    'dgPeripherals.Rows.Insert(0, dgPeripherals.Rows.NewRow())
    'dgPeripherals.Refresh()
     
    'But it does  display me a new row insert recrods to the grid.
    'I have added above code inside the hander event of the Add button as follows ,
     
     
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls.UI.GridViewColumn
     
    Private Sub FormTeleic_Load(sender As Object, e As EventArgs)
            Me.dgPeripherals = New Telerik.WinControls.UI.RadGridView()
            GeneratePeripheralsGridColumns()
    End Sub
     
     Private Sub dgPeripherals_CommandCellClick(sender As Object, e As EventArgs)
             
                Dim gCommand As GridCommandCellElement = TryCast(sender, GridCommandCellElement)
                Dim result As DialogResult
                If gCommand.ColumnInfo.Name = "clmAdd" Then
                    dgPeripherals.AllowAddNewRow = True
                    dgPeripherals.Rows.Insert(0, dgPeripherals.Rows.NewRow())
                    dgPeripherals.Refresh()
                End If
    End Sub
     
     
     
    Private Sub GeneratePeripheralsGridColumns()
     
            ' TEXT COLUMN
            Dim clmItemSN As New GridViewTextBoxColumn()
            clmItemSN.HeaderText = "Item S/N"
            clmItemSN.Width = 100
     
            Dim clmItemName As New GridViewTextBoxColumn()
            clmItemName.HeaderText = "Item Name"
            clmItemName.Width = 100
          
            Dim clmAdd As New GridViewCommandColumn()
            clmAdd.Name = "clmAdd"
            clmAdd.UseDefaultText = True
            clmAdd.DefaultText = "Add"
            clmAdd.HeaderText = "Add"
     
            dgPeripherals.Columns.Add(clmItemSN)
            dgPeripherals.Columns.Add(clmItemName)   
            dgPeripherals.Columns.Add(clmAdd)
      
    End Sub
     
    ' What I want is to add a new row to the excisting grid when clicked on the Add Button on the previous row
    'The default behaviour is , it adds  a new row to the grid when I press enter on the last text cell , but I want this to happend upon add button click event.
    'Is this possible to achive with Teleric Grids ? Can somebody help me please ?
    'I'm new to teleric grid , please bear with me if I missed anything,
    'Thanks in advance.
  2. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 16 Jul 2015 Link to this post

    Hello Nipuna,

    Thank you for writing.

    From you code snippet I understand that you are having a RadGridView with a GridViewCommandColumn and you would like to add a new row in your grid on a click event in the command cell. Please check my code snippet below: 
    Partial Public Class Form1
     
        Public Sub New()
            InitializeComponent()
     
            Me.BindGrid()
            Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
            AddHandler Me.RadGridView1.CommandCellClick, AddressOf RadGridView1_CommandCellClick
        End Sub
     
        Private Sub BindGrid()
            Dim decimalColumn As New GridViewDecimalColumn()
            decimalColumn.Name = "DecimalColumn"
            Me.RadGridView1.MasterTemplate.Columns.Add(decimalColumn)
     
            Dim textBoxColumn As New GridViewTextBoxColumn()
            textBoxColumn.Name = "TextBoxColumn"
            Me.RadGridView1.MasterTemplate.Columns.Add(textBoxColumn)
     
            Dim commandColumn As New GridViewCommandColumn()
            commandColumn.Name = "CommandColumn"
            Me.RadGridView1.MasterTemplate.Columns.Add(commandColumn)
     
            For i As Integer = 0 To 19
                Me.RadGridView1.Rows.Add(i, "Name " & i, "Add Row")
            Next
        End Sub
     
        Private Sub RadGridView1_CommandCellClick(sender As Object, e As EventArgs)
            'Me.RadGridView1.Rows.Add(20, "New Name", "Add Row")
            'Me.RadGridView1.Rows.AddNew()
            Me.RadGridView1.Rows.Insert(0, Me.RadGridView1.Rows.NewRow())
        End Sub
     
    End Class

    Additional information on how rows can be manipulated you can find in this section of our documentation: RadGridView | Rows.

    I hope this help. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nipuna
    Nipuna avatar
    2 posts
    Member since:
    Jul 2015

    Posted 16 Jul 2015 Link to this post

    Hi Hristo ,

    Thank for the reply , I will try this out and get back to you soon , Thanks a lot for the reply :)

     

  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 17 Jul 2015 Link to this post

    Hi Nipuna,

    Thank you for writing back.

    I hope that the proposed solution would fit to your project. Please take as much time as you need to investigate it and do not hesitate to write back, should you have further questions.

    I hope this helps.

    Regards,
    Hristo Merdjanov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top