Adding And Inserting Rows - WinForms GridView Control
Có thể bạn quan tâm
When RadGridView is in unbound mode, you can add new rows to the Rows collection.
Adding rows to RadGridView
For example, if the grid control contains four columns – GridViewTextBoxColumn, GridViewDecimalColumn, GridViewDateTimeColumn and GridViewCheckBoxColumn you can add an empty row as it is demonstrated in the code snippet below.
The RadGridView.Rows.AddNew() method adds an empty row and allows the user to enter a value for each column cells’:
Add an empty row
radGridView1.Rows.AddNew(); RadGridView1.Rows.AddNew()Figure 1: Add a blank new row
The RadGridView.Rows.Add(value-for-first-column, value-for-second-column, value-for-third-column) method adds a new row with the specified values. You can use the following code snippet to add values for each column:
Add a new row with values
radGridView1.Rows.Add("Adding New Row", 12.5, DateTime.Now, true); RadGridView1.Rows.Add("Adding New Row", 12.5, DateTime.Now, True)Figure 2: Add new row with data in it
You can also add rows by creating an instance of GridViewDataRowInfo and adding it to the Rows collection of RadGridView:
Add a GridViewDataRowInfo
GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(this.radGridView1.MasterView); rowInfo.Cells[0].Value = "GridViewDataRowInfo"; rowInfo.Cells[1].Value = 11.4; rowInfo.Cells[2].Value = DateTime.Now.AddDays(5); rowInfo.Cells[3].Value = true; radGridView1.Rows.Add(rowInfo); Dim rowInfo As New GridViewDataRowInfo(Me.RadGridView1.MasterView) rowInfo.Cells(0).Value = "GridViewDataRowInfo" rowInfo.Cells(1).Value = 11.4 rowInfo.Cells(2).Value = DateTime.Now.AddDays(5) rowInfo.Cells(3).Value = True RadGridView1.Rows.Add(rowInfo)Figure 3: Add new row by creating an instance first
Inserting rows in RadGridView
Rows can be inserted at a specified position by using the Insert method of the Rows collection. Below you can see an example of this functionality:
Insert a GridViewDataRowInfo
GridViewDataRowInfo dataRowInfo = new GridViewDataRowInfo(this.radGridView1.MasterView); dataRowInfo.Cells[0].Value = "Inserted Row"; dataRowInfo.Cells[1].Value = 1156.54; dataRowInfo.Cells[2].Value = DateTime.Now.AddDays(14); radGridView1.Rows.Insert(2, dataRowInfo); Dim dataRowInfo As New GridViewDataRowInfo(Me.RadGridView1.MasterView) rowInfo.Cells(0).Value = "Inserted Row" rowInfo.Cells(1).Value = 1154.54 rowInfo.Cells(2).Value = DateTime.Now.AddDays(14) RadGridView1.Rows.Insert(2, dataRowInfo)Figure 4: Insert row to a specific position
Conditional Formatting Rows
Creating custom rows
Drag and Drop
Formatting Rows
GridViewRowInfo
Iterating Rows
New Row
Painting Rows
Từ khóa » Visual Basic Datagridview Insert Row
-
Add Row To Datagridview Programmatically Code Example
-
DataGridView Adding Rows And Columns In VB.NET
-
How Do I Add Records To A DataGridView In VB.Net? - Stack Overflow
-
How To Add A Row To DataGridView From TextBox In VB.NET ...
-
VB.NET Tutorial 34 : DataGridView Example (Adding Row) In Visual ...
-
Datagridview Add Rows - YouTube
-
Add Rows In To Bounded Datagridview - MSDN - Microsoft
-
DataGridViewRowCollection.Insert Method (System.Windows.Forms)
-
Adding New Row In Datagridview [SOLVED] - - Daniweb
-
Programmatically Add New Rows To An Unbound DataGridView ...
-
[Solved] Datagridview Add Empty Rows ? - CodeProject
-
How To Add Row To DataGridView In Visual Basic (Visual Studio)
-
How To Add A Row To DataGridView From TextBox In VB.NET
-
Prevent (Disable) Adding New Row To DataGridView In Windows ...