By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,343 Members | 925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,343 IT Pros & Developers. It's quick & easy.

datagrid -newrow()

P: n/a
I only one datagrid, and one button.
the buttonwill process ' dtmyTable.newrow()' , However, the datagrid seems
didn't add the row byitself ??
Thanks
Nov 20 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Agnes,

Is your code something as?
dim dr as datarow = dtMyTable.NewRow()
dtMytable.rows.add(dr)

When not make it that way (you can do it in one sentence as well)?

I hope that helps?

:-)

Cor
"
I only one datagrid, and one button.
the buttonwill process ' dtmyTable.newrow()' , However, the datagrid seems didn't add the row byitself ??
Thanks

Nov 20 '05 #2

P: n/a
Thanks Cor,
There is a property called dtMyTable.insertat (dr,position)
my grid got 5 rows, i need to insert the new row between 2nd and 3rd
I try dtMyTable.insertat(dr,2) . but it seems fail .. it still add to the
last row.
Can we do that "insert a row in specific row" ???
thanks again

"Cor Ligthert" <no**********@planet.nl> 秎ン
news:e6**************@TK2MSFTNGP12.phx.gbl い级糶...
Agnes,

Is your code something as?
dim dr as datarow = dtMyTable.NewRow()
dtMytable.rows.add(dr)

When not make it that way (you can do it in one sentence as well)?

I hope that helps?

:-)

Cor
"
I only one datagrid, and one button.
the buttonwill process ' dtmyTable.newrow()' , However, the datagrid

seems
didn't add the row byitself ??
Thanks


Nov 20 '05 #3

P: n/a
Hi Agnes,

I have seen this problem before and I did not get it to work.

Maybe somebody else know the problem.

Cor
There is a property called dtMyTable.insertat (dr,position)
my grid got 5 rows, i need to insert the new row between 2nd and 3rd
I try dtMyTable.insertat(dr,2) . but it seems fail .. it still add to the
last row.
Can we do that "insert a row in specific row" ???
thanks again

Nov 20 '05 #4

P: n/a
Only reflected in the DataRowsCollection returned by Rows.

Dim nr As DataRow
Dim x As Int32

nr = DataSet11.Tables(0).NewRow
nr(0) = "Ox"
DataSet11.Tables(0).Rows.InsertAt(nr, 2)

For x = 0 To DataSet11.Tables(0).Rows.Count - 1

Debug.WriteLine(DataSet11.Tables(0).Rows(x).Item(0 ).ToString())

Next
//OUTPUT

Highfield Road
Abbey Close
Ox
Bower Way
Bower Way
Roadway To Hell
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
Thanks Cor,
There is a property called dtMyTable.insertat (dr,position)
my grid got 5 rows, i need to insert the new row between 2nd and 3rd
I try dtMyTable.insertat(dr,2) . but it seems fail .. it still add to the
last row.
Can we do that "insert a row in specific row" ???
thanks again

"Cor Ligthert" <no**********@planet.nl> 秎ン
news:e6**************@TK2MSFTNGP12.phx.gbl い级糶...
Agnes,

Is your code something as?
dim dr as datarow = dtMyTable.NewRow()
dtMytable.rows.add(dr)

When not make it that way (you can do it in one sentence as well)?

I hope that helps?

:-)

Cor
"
I only one datagrid, and one button.
the buttonwill process ' dtmyTable.newrow()' , However, the datagrid

seems
didn't add the row byitself ??
Thanks



Nov 20 '05 #5

P: n/a
I search from other newsgroup . some
said-------------------------------------------
The MSDN says that InsertAt could not be a solution to your problem. I think
this is an answer, that is: there is nothing wrong in the way you use the
InsertAt, but simply it cannot do what you expect it does. In other words,
it makes no much sense insisting in solving this matter using InsertAt, but
find alternatives like moving the rows in other DataTable object in the
order you like.
------------------------------------------------------------
"Cor Ligthert" <no**********@planet.nl> 秎ン
news:OI**************@TK2MSFTNGP12.phx.gbl い级糶...
Hi Agnes,

I have seen this problem before and I did not get it to work.

Maybe somebody else know the problem.

Cor
There is a property called dtMyTable.insertat (dr,position)
my grid got 5 rows, i need to insert the new row between 2nd and 3rd
I try dtMyTable.insertat(dr,2) . but it seems fail .. it still add to the last row.
Can we do that "insert a row in specific row" ???
thanks again


Nov 20 '05 #6

P: n/a
Dim mdt As DataTable = Me.DataSet11.Tables(0).Copy

This will sort it


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I search from other newsgroup . some
said-------------------------------------------
The MSDN says that InsertAt could not be a solution to your problem. I think this is an answer, that is: there is nothing wrong in the way you use the
InsertAt, but simply it cannot do what you expect it does. In other words,
it makes no much sense insisting in solving this matter using InsertAt, but find alternatives like moving the rows in other DataTable object in the
order you like.
------------------------------------------------------------
"Cor Ligthert" <no**********@planet.nl> 秎ン
news:OI**************@TK2MSFTNGP12.phx.gbl い级糶...
Hi Agnes,

I have seen this problem before and I did not get it to work.

Maybe somebody else know the problem.

Cor
There is a property called dtMyTable.insertat (dr,position)
my grid got 5 rows, i need to insert the new row between 2nd and 3rd
I try dtMyTable.insertat(dr,2) . but it seems fail .. it still add to the last row.
Can we do that "insert a row in specific row" ???
thanks again



Nov 20 '05 #7

P: n/a
Hi Terry

Because of your message I was thinking what was the kull again.

We had the same conclussion.

:-)

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("bla")
dt.Columns.Add("Oxes")
Dim mystring() As String = {"Highfield Road", _
"Abbey(Close)", "Bower(Way)", "Bower(Way)", "Roadway To Hell"}
For i As Integer = 0 To mystring.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = mystring(i)
dt.Rows.Add(dr)
Next
Dim dr2 As DataRow = dt.NewRow
dr2(0) = "Ox"
dt.Rows.InsertAt(dr2, 2)
Dim dtnew As DataTable = dt.Copy
dt = dtnew.Copy
DataGrid1.DataSource = dt
End Sub
Nov 20 '05 #8

P: n/a
Cor, your code work great.
However, my gird is master-detail relationship.
during my form load, My master and detail use the same dataset and with the
constraint key
I try dgDetail.datasource = dt
it seems reset my relationship ,all data are shown .......

"Cor Ligthert" <no**********@planet.nl> 秎ン
news:uh**************@TK2MSFTNGP12.phx.gbl い级糶...
Hi Terry

Because of your message I was thinking what was the kull again.

We had the same conclussion.

:-)

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("bla")
dt.Columns.Add("Oxes")
Dim mystring() As String = {"Highfield Road", _
"Abbey(Close)", "Bower(Way)", "Bower(Way)", "Roadway To Hell"}
For i As Integer = 0 To mystring.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = mystring(i)
dt.Rows.Add(dr)
Next
Dim dr2 As DataRow = dt.NewRow
dr2(0) = "Ox"
dt.Rows.InsertAt(dr2, 2)
Dim dtnew As DataTable = dt.Copy
dt = dtnew.Copy
DataGrid1.DataSource = dt
End Sub

Nov 20 '05 #9

P: n/a
> Cor, your code work great.
However, my gird is master-detail relationship.
during my form load, My master and detail use the same dataset and with the constraint key
I try dgDetail.datasource = dt
it seems reset my relationship ,all data are shown ....... daInv.fill(dsInvoice,"invoiceheader")
daInv.fill(dsInvoice,"invoicedetail")

dsInvoice.relations.add("fk_invno,"............... ..................etc)

Me.dgHeader.DataSource = dsInvoice
Me.dgHeader.DataMember = "invoiceheader"

Me.dgDetail.DataSource = dsInvoice
Me.dgDetail.DataMember = "Header.fK_invno"

So , as i choose the record in Header, the detail will switch too.......


"Cor Ligthert" <no**********@planet.nl> 秎ン
news:uh**************@TK2MSFTNGP12.phx.gbl い级糶...
Hi Terry

Because of your message I was thinking what was the kull again.

We had the same conclussion.

:-)

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("bla")
dt.Columns.Add("Oxes")
Dim mystring() As String = {"Highfield Road", _
"Abbey(Close)", "Bower(Way)", "Bower(Way)", "Roadway To Hell"}
For i As Integer = 0 To mystring.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = mystring(i)
dt.Rows.Add(dr)
Next
Dim dr2 As DataRow = dt.NewRow
dr2(0) = "Ox"
dt.Rows.InsertAt(dr2, 2)
Dim dtnew As DataTable = dt.Copy
dt = dtnew.Copy
DataGrid1.DataSource = dt
End Sub


Nov 20 '05 #10

P: n/a
Actually, you can to an update on your adapter if you want or if you dont
have one, just to a Table.AcceptChanges and this will put the data in the
right order.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:OL**************@TK2MSFTNGP09.phx.gbl...
Cor, your code work great.
However, my gird is master-detail relationship.
during my form load, My master and detail use the same dataset and with

the
constraint key
I try dgDetail.datasource = dt
it seems reset my relationship ,all data are shown .......

daInv.fill(dsInvoice,"invoiceheader")
daInv.fill(dsInvoice,"invoicedetail")

dsInvoice.relations.add("fk_invno,"............... ..................etc)

Me.dgHeader.DataSource = dsInvoice
Me.dgHeader.DataMember = "invoiceheader"

Me.dgDetail.DataSource = dsInvoice
Me.dgDetail.DataMember = "Header.fK_invno"

So , as i choose the record in Header, the detail will switch too.......


"Cor Ligthert" <no**********@planet.nl> 秎ン
news:uh**************@TK2MSFTNGP12.phx.gbl い级糶...
Hi Terry

Because of your message I was thinking what was the kull again.

We had the same conclussion.

:-)

Cor

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("bla")
dt.Columns.Add("Oxes")
Dim mystring() As String = {"Highfield Road", _
"Abbey(Close)", "Bower(Way)", "Bower(Way)", "Roadway To Hell"}
For i As Integer = 0 To mystring.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = mystring(i)
dt.Rows.Add(dr)
Next
Dim dr2 As DataRow = dt.NewRow
dr2(0) = "Ox"
dt.Rows.InsertAt(dr2, 2)
Dim dtnew As DataTable = dt.Copy
dt = dtnew.Copy
DataGrid1.DataSource = dt
End Sub



Nov 20 '05 #11

P: n/a
Hi Terry,

The first one could be done, the second one (acceptchanges) is written
somewhere I know, however that is the wrong solution. After that there are
no updates anymore processed.

Cor
Actually, you can to an update on your adapter if you want or if you dont
have one, just to a Table.AcceptChanges and this will put the data in the
right order.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Nov 20 '05 #12

P: n/a
Hi Agnes,

Can you try it yourself what the same idea with the dataset.copy does?

dim dsnew as dataset = ds.copy
ds = dsnew.copy

Cor
Nov 20 '05 #13

P: n/a
Try your code, this time the detail grid won't show all the data.....
But as I run dt.insertat(dr,dgDetail.currentrowindex)
I test the currentrowindex which return correct row number. However, it
always insert the wrong row.
And this method only allow me to add one row.... [I put all the code in the
button's click event]
after press "once", it work but in wrong row, secondtime. no response.

"Cor Ligthert" <no**********@planet.nl> 秎ン
news:%2****************@TK2MSFTNGP09.phx.gbl い级糶...
Hi Agnes,

Can you try it yourself what the same idea with the dataset.copy does?

dim dsnew as dataset = ds.copy
ds = dsnew.copy

Cor

Nov 20 '05 #14

P: n/a
Agnes,

Strange this works for me

Can you try it, do not forget to set that AllowSorting to false with this
method otherwise you get problems later.

I hope this helps?

Cor

\\\
Dim ds As New DataSet
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable("bla")
ds.Tables.Add(dt)
dt.Columns.Add("Oxes")
DataGrid1.AllowSorting = False
Dim mystring() As String = {"Highfield Road", _
"Abbey(Close)", "Bower(Way)", "Roadway To Hell"}
For i As Integer = 0 To mystring.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = mystring(i)
dt.Rows.Add(dr)
Next
DataGrid1.DataSource = ds.Tables(0)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dr2 As DataRow = ds.Tables(0).NewRow
dr2(0) = "Ox"
ds.Tables(0).Rows.InsertAt(dr2, DataGrid1.CurrentRowIndex)
Dim dsnew As DataSet = ds.Copy
ds = dsnew.Copy
DataGrid1.DataSource = ds.Tables(0)
End Sub
Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.