Ticket Q524021
Visible to All Users

GridView - How to add a new row to a specific position

created 12 years ago

How do I make a new row that is added to the GridView appear as the last row?

Comments (2)
DevExpress Support Team 12 years ago

    Hello,
    As far as I understand, you wish to change a NewItemRow position. If so, set the GridView.OptionsView.NewItemRowPositionproperty to Bottom.
    If it does not help you, would you please clarify your task in greater detail?

      Thanks Alexey.
      To be more clear, if the GridView.OptionsView.NewItemRowPosition property is set to top, then a "row holder" appears in the topmost row. I use the gridview to view information. When information is added to the gridview, I want it to appear in the topmsot row. I do not want to have a placeholder or empty row anywhere. When I add information, or a new row of data to the gridview, how do i make it appear in the first row. (or the last row for that matter.

      Answers approved by DevExpress Support

      created 12 years ago (modified 7 years ago)

      Hello,

      If no sorting is applied, GridControl displays data as it is located in the underlying data source. When you add a new row, it is added to the last position and GridControl will display it as the bottommost row.
      So, if you want to add a new row to the topmost position, use the data source methods. For example, for DataTable you can use the following code snippet:

      C#
      Random rand = new Random(); DataTable dt = gridControl1.DataSource as DataTable; DataRow newRow = dt.NewRow(); newRow["ID"] = rand.Next(0, 100); newRow["Info"] = "Info" + (gridView1.RowCount - 1).ToString(); dt.Rows.InsertAt(newRow, 0);

      Please see the attached project for more information. I hope you find this information useful and am looking forward to your results once you try this solution.

        Comments (3)

          Hi, Are you finding it?
          Video Tutorials: https://www.youtube.com/watch?v=2139TgNMD6s

          Visual Basic 6
          Imports DevExpress.XtraGrid Public Class frmUserGroup Private dt As DataTable Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click Dim dr As DataRow = dt.NewRow() dr(0) = "0" & GridView1.RowCount + 1 dr(1) = txtUseGroUniqueName.Text dr(2) = txtUseGroDisplayName.Text dr(3) = txtUseGroDescription.Text dr(4) = Convert.ToInt16(chkUseGroStatus.CheckState) dt.Rows.Add(dr) GridControl1.DataSource = dt Dim rp As New DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit() _ With {.ValueChecked = "1", .ValueUnchecked = "0", .ValueGrayed = ""} GridView1.Columns(4).ColumnEdit = rp End Sub Private Sub frmUserGroup_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load dt = New DataTable dt.Columns.Add("No") dt.Columns.Add("Unique") dt.Columns.Add("Display") dt.Columns.Add("Description") dt.Columns.Add("Status") GridControl1.DataSource = dt End Sub End Class

            plz make this code in c#

            DevExpress Support Team 9 years ago

              Hello,

              I've created a separate ticket on your behalf (T416319: XtraGridControl - How to add a new row). It has been placed in our processing queue and will be answered shortly.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.