databinding & active row

  • Thread starter Thread starter T.Jackson
  • Start date Start date
T

T.Jackson

Hi guys,
I'm new to .net & i've got a problem with regards to datasets & data
binding.

Here goes,
I've got a data grid & the active row (position) is the 3 row.
Now, i take this data set, & pass it to a seperate form, where i want to be
able to edit the details of this row.
So, in the load event of this new form, i bind the necessary columns of the
table to the required controls.

Problem -
The data displayed is that of the first row!!!!!

is this a behaviour of .Net,
where when data is bound to a control, the data will always be displayed
from the very first Row,
in other words....
is the current row in the datagrid totally independant of the dataset
(source), & has no effect on this??
 
Hi TJ,

Before I try to get it completly what you want to do,

Have a look at currencymanager, that keeps track of the current position in
a table.

I hope this was where you was looking for?

Cor
 
Hi Cor,
I've got the answer for this, could u please check thsi for me,

Consider the following scenario.

1. A datagrid with 5 records
2. The 2 row has been deleted off (but acceptchanges method has not been
called).
3. The current row position is 2 in the data grid.
4. I would like to get hold of the above datarow, but cannot use the
"CurrentRowPostion"
as a parameter for the DataGrid.DataSet.Tables(0).Rows(<Row Number>),
as if i were to do this, then i'd be accessing the deleted row & not the
row in the datagrid.

So, HOW do i get hold of the current row?????
 
Hi TJ,

Try this sample I did make.
Open a new windows form project and paste this code in.
\\\You need to drag 2 datagrids and 2 buttons on the form.
Dim ds As New DataSet
Dim dv As New DataView
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Button1.Text = "Delete"
Me.Button2.Text = "New"
For i As Integer = 0 To 3
Dim dc As New DataColumn(Chr(i + 65))
dt.Columns.Add(dc)
Next
For i As Integer = 0 To 11
dt.Rows.Add(dt.NewRow)
For y As Integer = 0 To dt.Columns.Count - 1
dt.Rows(i)(y) = Chr(i + 65)
Next
Next
ds.Tables.Add(dt)
dv = New DataView(ds.Tables(0))
dv.Sort = "b Desc"
DataGrid1.DataSource = dv
DataGrid2.DataSource = ds.Tables(0)
Me.DataGrid2.ReadOnly = True
Me.DataGrid2.CaptionVisible = False
Me.DataGrid2.ColumnHeadersVisible = False
Me.DataGrid2.DataMember = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
dv.Delete(DirectCast(BindingContext(dv), CurrencyManager).Position)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Static a As Integer = 12
Dim dr As DataRow = dt.NewRow
dt.Rows.Add(dr)
For y As Integer = 0 To dt.Columns.Count - 1
dr(y) = Chr(a + 65)
Next
a += 1
End Sub
 
Back
Top