473,387 Members | 3,781 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,387 software developers and data experts.

Adding a new row to a datagrid bound to a dataset.

Hello,
I have a problem whereby I have a datagrid and and extra field all bound to the same dataset. I can easily edit rows in the dataset by changing the bindingposition in the MyGrid_currentcellchanged event of Mygrid, using the following function
Private Function GetBindingPosition(ByVal IntMatchValue As Integer, ByVal MyMatchField As String, ByVal MyDataTable As DataTable) As Integer
Dim i As Integer = 0
Dim blnValueFnd As Boolean

While (i <= (MyDataTable.Rows.Count - 1)) And Not blnValueFnd
If CType(MyDataTable.Rows(i).Item(MyMatchField), Integer) = IntMatchValue Then
blnValueFnd = True
Return i
Else
i = i + 1
End If
End While
End Function

..This gets the position in the dataset of a keyfield and thus sets the dataset binding position to this value and thus the extra field displays the relevant value.

The problem occurs when I wish to add a row, I can't find the binding position of therow because it does not exist in the dataset yet. If I update it b4 setting the binding position then it uses the previous binding position. The extra field cannot be part of the datagrid because it is too large and looks better kept seperate.

Any ideas would be appreciated.

Geri
Nov 20 '05 #1
1 1351
Hi Geraldine,

I am not sure if I understand your problem.

However yesterday I made and sended a sample what looks if it goes about
your problmem.

Have a look to it, it is not your solution with this I think you can get
your solution..

Cor

\\\
Private WithEvents dv As DataView
Private dt As New DataTable
Private Sub Form7_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
dt.Columns.Add("Wayne")
dt.Columns.Add("Ken")
For i As Integer = 0 To 4
Dim dr As DataRow = dt.NewRow
dr(0) = (i + 1).ToString
dr(1) = Chr(i + 65)
dt.Rows.Add(dr)
Next
dv = New DataView(dt)
Me.DataGrid1.DataSource = dv
End Sub

Private Sub dv_ListChanged(ByVal sender As Object, _
ByVal e As System.ComponentModel.ListChangedEventArgs) Handles
dv.ListChanged
If dt.Rows.Count < dv.Count Then
MessageBox.Show("New Row " & dv.Count.ToString)
End If
End Sub
End Class
///

Nov 20 '05 #2

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

Similar topics

2
by: Jim | last post by:
In my Win App, I have a datagrid that's bound to a dataset. When the form loads, the datagrid fills. How can I add an empty row to the end of the datagrid during a button click (similar to...
2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
3
by: Diego TERCERO | last post by:
Hi... I'm working on a tool for editing text resources for a family of software product my company produces. These text resources are found in a SQL Server database, in a table called...
2
by: Aaron Ackerman | last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried everything and I am at a loss. The using goes into add mode with the add button adds his data then updates with the update...
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: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
0
by: jy836 | last post by:
Hey all. I've created a DataGrid and bound it to a dataset, but I need to add several columns. The columns that I need to add have to be in the middle of the ones that are already there (as opposed...
3
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.