473,395 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DataGrid Update?

I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?

Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?

Thanks,
--
Strah @ Langan
Nov 20 '05 #1
8 2003
Can I see the code you are using?

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?

Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?

Thanks,
--
Strah @ Langan

Nov 20 '05 #2
There is a lot of code spread in 4 projects making a solution.
I'll try to post code snippets relevant to what I want to achieve.
Public Sub CreateIntesectionTable_

(ByRef ds As System.Data.DataSet, ByRef dg As
Windows.Forms.DataGrid)

' Call custom function to add a DataTable to the DataSet

Dim sTableName As String = "IntesectionData"

Dim dt As DataTable = AddTableToDataSet(ds, sTableName)

' Call custom function to add DataColumns to the DataTable created
above.

AddColumnToTable(dt, "Intersection_Name", _

"Intersection_Name", System.Type.GetType("System.String"), _

"", True, False, False, False, 0, 1)

AddColumnToTable(dt, "Condition", "Condition", _

System.Type.GetType("System.String"), "", True, False, False,
False, 0, 1)

'... Add more columns

' Represent data from DataTable in DataGrid

ShowTableInDataGrid(dt, dg)

End Sub

Public Sub ShowTableInDataGrid(ByRef dt As DataTable, ByRef dg As
System.Windows.Forms.DataGrid)

Dim dv As New DataView()

dv = New DataView(dt)

dg.DataSource = dv

End Sub
There is a button on the form that a row from the DataTable. At the same
time
it captures a row index of the deleted row. When a row is deleted from the
table,
it automatically disappears from the DataGrid. The code looks something like
this:

Private iRowIndex as Integer = 0

Private Sub btnEdit_Click_

(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnEdit.Click

' .... Some code here ....

iRowIndex = Me.dgNetworkSummary.CurrentRowIndex

ds.Tables("IntesectionData").Rows(iRowIndex).Delet e()

' .... Some code here ....

End Sub

There is also a button that appends new row to the DataTable
Private Sub btnSubmit_Click_

(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSubmit.Click

' Some code here...

Dim rowVals(2) As Object

rowVals(0) = someValue0

rowVals(1) = someValue1

rowVals(2) = someValue2

Dim rc As DataRowCollection

Dim myNewRow As DataRow

rc = dt.Rows 'Note: dt = ds.Tables("IntesectionData")

myNewRow = rc.Add(rowVals)

' Some code here...

End Sub
The above procedure adds a new row to the DataTable (IntesectionData). The
row automaticaly appears at the bottom of DataGrid too, which is expected
behavior.

Now, I want to change the btnSubmit_Click() procedure to insert a
new row at the iRowIndex position in the DataTable and show
that row in the right position in the DataGrid as well. Here
is modified procedure.

Private Sub btnSubmit_Click_

(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnSubmit.Click

' Some code here...

Dim insertedRow As DataRow

insertedRow = dt.NewRow 'Note: dt = ds.Tables("IntesectionData")

insertedRow(0) = Value0

insertedRow(1) = Value1

insertedRow(2) = Value2

dt.Rows.InsertAt(insertedRow, iRowIndex)

' This loops proves that new row is inserted

' on the right position in the DataTable, however,

' in the DataGrid, the new row is appended at the

' bottom ???

For Each insertedRow In dt.Rows

Debug.WriteLine(insertedRow(0))

Next

' Some code here...

End Sub

The new, modified btnSubmit_Click() procedure inserts the new
row at the right location in the DataTable, however, in
the DataGrid, the new row is appended at the bottom.

My question is, if there is a way to show the new row
at the right position in the DataGrid too, or in other
words, to force the DataGrid to display the DataTable
correctly? So the DataGrid updates on the fly?

I hope I was clear enough, but please let me know if
you need more info. Thanks for your help.
--
Strah @ Langan
"scorpion53061" <sc****************************@yahoo.com> wrote in message
news:O5**************@TK2MSFTNGP10.phx.gbl...
Can I see the code you are using?

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?

Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?

Thanks,
--
Strah @ Langan


Nov 20 '05 #3
never mind, I got it. Thanks
--
Strah @ Langan

"scorpion53061" <sc****************************@yahoo.com> wrote in message
news:O5**************@TK2MSFTNGP10.phx.gbl...
Can I see the code you are using?

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?

Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?

Thanks,
--
Strah @ Langan


Nov 20 '05 #4
Please post the solution you came up with.

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
never mind, I got it. Thanks
--
Strah @ Langan

"scorpion53061" <sc****************************@yahoo.com> wrote in message news:O5**************@TK2MSFTNGP10.phx.gbl...
Can I see the code you are using?

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?

Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?

Thanks,
--
Strah @ Langan



Nov 20 '05 #5


DataTable.AcceptChanges() does the job. It forces grid to recognize changes
and accepts it as well.
Thanks,
--
Strah @ Langan

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
never mind, I got it. Thanks
--
Strah @ Langan

"scorpion53061" <sc****************************@yahoo.com> wrote in message news:O5**************@TK2MSFTNGP10.phx.gbl...
Can I see the code you are using?

"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I bound a DataGrid to a table (I tried with a DataView too).
I removed the row from the table, and then inserted a new
row at the same row index. the table gets the row to the
right position, but the bound DataGrid does not pick up
and appends the inserted row at the bottom of the grid,
not the right position?!?

Any ideas how to make the DataGrid pick up the changes
done in the table - to show the inserted row at the right
position?

Thanks,
--
Strah @ Langan



Nov 20 '05 #6
Actually,

DataTable.AcceptChanges() does the job. It forces grid to recognize
changes and accepts it as well.

Thahnks

Strah

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #7
Strahimir,
Notr that AcceptChanges will also mark all the rows as unchanged so you
won't be able to update back to a database.

Ron Allen
"Strahimir Antoljak" <st***@netzero.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Actually,

DataTable.AcceptChanges() does the job. It forces grid to recognize
changes and accepts it as well.

Thahnks

Strah

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #8
Ron,

thanks for your input. I think that I am even aware
of that, but strangely enough, there is no database.

I started developing a Win app that accepts some
user input and based on that it builds Excel table
and populates certain cells with formulas, all based
on the user input as the table can have arbitrary number
of rows and columns, and formulas are dependant on that.

Now the app has grown, and users wanted to save some
of their input, and I actually save all input in the
XML file, not really to a database. So, the AcceptChanges
method does the job for what I needed it.

What you are saying Ron, belongs to a bit more
complicated scenario which would require a bit more
sophisticated UI for the app.

But thanks for the warning anyway.

Happy New Year to all,

Strah
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
2
by: Manish | last post by:
Hey folks I am having a weird problem in ASP .Net. My page is in C#. I have a datagrid, which populates based on selection in drop down box on ASP page. This datagrid has template textbox colum in...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
3
by: D. Shane Fowlkes | last post by:
I have a Datagrid which in theory, should allow you to edit and update the records. I've stripped my test page down so that it's only attempting to update one field - "description". Yet when I...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
5
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.