How do I make a new row that is added to the GridView appear as the last row?
GridView - How to add a new row to a specific position
Answers approved by DevExpress Support
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.
Hi, Are you finding it?
Video Tutorials: https://www.youtube.com/watch?v=2139TgNMD6s
Visual Basic 6Imports 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
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.
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.