Groups | Blog | Home
all groups > dotnet academic > march 2005 >

dotnet academic : VB.Net DataGrid


Vv via .NET 247
3/16/2005 4:55:05 AM
(Type your message here)

--------------------------------
From: Vv

Hi. Im trying to insert a row in winform datagrid at a particular location. But everytime it is appending the row in the end. Could anybody help...

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

Peter van der Goes
3/16/2005 10:04:08 AM

[quoted text, click to view]

The behavior you are experiencing is by design. You cannot "insert" a new
row in the middle of the grid.
The DataGrid provides (by default) an open row at the bottom for new data,
which is subsequently inserted into a DataSet associated with the DataGrid.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Greg Dunn
3/17/2005 11:16:52 AM
The order of the rows in the DataGrid is determined by the Sort property of
the DefaultView of the DataTable that feeds the grid. Say you load that
table in the form's load event:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.daAuthors.Fill(Me.objdsPubs)
Me.DataGrid1.DataSource = Me.objdsPubs.authors
vueAuthors = Me.objdsPubs.authors.DefaultView
vueAuthors.Sort = "au_lname, au_fname"
End Sub

Then when you add a new row, it will automatically be displayed at the
appropriate place in the sort order:

Private Sub btnInsertRow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnInsertRow.Click
Dim rowX As DataRow
rowX = Me.objdsPubs.authors.NewRow
rowX("au_id") = "999-99-9999"
rowX("au_lname") = "Fubar"
rowX("au_fname") = "Farley"
rowX("phone") = "510.555.1234"
rowX("address") = "134 34th Stree"
rowX("city") = "Minneapolis"
rowX("state") = "MN"
rowX("zip") = "44444"
rowX("contract") = 1
Me.objdsPubs.authors.Rows.Add(rowX)
End Sub

Greg Dunn


[quoted text, click to view]

AddThis Social Bookmark Button