469,898 Members | 1,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

Firing an update off of a single change in a datagrid

I want to fire a database update off of a single change to a single cell in
the datagrid. This apparently cannot be done using keypress, keyup, keydown,
etc. I've read George Shepard's FAQ and while I may have overlooked it, I
have not found an answer. I now am using the CurrentCellChanged event, and
this is satisfactory IF the user moves off of the cell before closing the
form. An obvious alternative would be to check for changes before closing
the form, but I would rather do it at the moment the cell gets changed.
Nov 21 '05 #1
5 1443
Hi,

You can use the currency managers current changed event to detect
changes.

http://www.windowsformsdatagridhelp....6-9cc458453630

Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager
Dim da As OleDbDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim strSQL As String
Dim conn As OleDbConnection
Dim cmd As OleDbCommandBuilder

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)
da.Fill(ds, "Categories")
cmd = New OleDbCommandBuilder(da)

DataGrid1.DataSource = ds.Tables("Categories")

cm = CType(Me.BindingContext(DataGrid1.DataSource), CurrencyManager)
End Sub
Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Dim dt As DataTable
Try
dt = ds.Tables("Categories").GetChanges()
If dt.Rows.Count > 0 Then
da.Update(ds, "Categories")
ds.AcceptChanges()
End If
Catch
End Try
End Sub

Ken
------------------
"Earl" <br******@newsgroups.nospam> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
I want to fire a database update off of a single change to a single cell in
the datagrid. This apparently cannot be done using keypress, keyup, keydown,
etc. I've read George Shepard's FAQ and while I may have overlooked it, I
have not found an answer. I now am using the CurrentCellChanged event, and
this is satisfactory IF the user moves off of the cell before closing the
form. An obvious alternative would be to check for changes before closing
the form, but I would rather do it at the moment the cell gets changed.

Nov 21 '05 #2
Thanks Ken. I'm already using the currency manager (with a dataview) and
while it intercepts my changes WITHIN a cell, it does not catch the Delete
key with a row selected.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hi,

You can use the currency managers current changed event to detect
changes.

http://www.windowsformsdatagridhelp....6-9cc458453630

Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager
Dim da As OleDbDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim strSQL As String
Dim conn As OleDbConnection
Dim cmd As OleDbCommandBuilder

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)
da.Fill(ds, "Categories")
cmd = New OleDbCommandBuilder(da)

DataGrid1.DataSource = ds.Tables("Categories")

cm = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)
End Sub
Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Dim dt As DataTable
Try
dt = ds.Tables("Categories").GetChanges()
If dt.Rows.Count > 0 Then
da.Update(ds, "Categories")
ds.AcceptChanges()
End If
Catch
End Try
End Sub

Ken
------------------
"Earl" <br******@newsgroups.nospam> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
I want to fire a database update off of a single change to a single cell
in
the datagrid. This apparently cannot be done using keypress, keyup,
keydown,
etc. I've read George Shepard's FAQ and while I may have overlooked it, I
have not found an answer. I now am using the CurrentCellChanged event, and
this is satisfactory IF the user moves off of the cell before closing the
form. An obvious alternative would be to check for changes before closing
the form, but I would rather do it at the moment the cell gets changed.

Nov 21 '05 #3
Sorry for what was somewhat of a confusing response ... basically where I'm
at right now is that the currency manager doesn't do any more than the
CurrentCellChanged event does. To trigger the currency manager, I would
still have to move out of the cell.

So I went past that, and decided to just use the OK/Close button to trigger
an update in case the user had NOT moved out of the cell. This of course
creates another issue -- what if the user had deleted a row -- with the
Delete key instead of the button? Well, I could call for a delete command
there, but then it appeared that I would have to derive a custom datagrid to
capture the delete key.

I'm tired, it's late, I've been working with this damn datagrid for going on
2 years now, and if everything has to be derived to provide basic
functionality, I'm not real sure it's worth the bother. I'm tired of working
out data relations in the grid too. I sure hope they get it right in 2005.

"Earl" <br******@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Thanks Ken. I'm already using the currency manager (with a dataview) and
while it intercepts my changes WITHIN a cell, it does not catch the Delete
key with a row selected.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hi,

You can use the currency managers current changed event to detect
changes.

http://www.windowsformsdatagridhelp....6-9cc458453630

Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager
Dim da As OleDbDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim strSQL As String
Dim conn As OleDbConnection
Dim cmd As OleDbCommandBuilder

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)
da.Fill(ds, "Categories")
cmd = New OleDbCommandBuilder(da)

DataGrid1.DataSource = ds.Tables("Categories")

cm = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)
End Sub
Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Dim dt As DataTable
Try
dt = ds.Tables("Categories").GetChanges()
If dt.Rows.Count > 0 Then
da.Update(ds, "Categories")
ds.AcceptChanges()
End If
Catch
End Try
End Sub

Ken
------------------
"Earl" <br******@newsgroups.nospam> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
I want to fire a database update off of a single change to a single cell
in
the datagrid. This apparently cannot be done using keypress, keyup,
keydown,
etc. I've read George Shepard's FAQ and while I may have overlooked it, I
have not found an answer. I now am using the CurrentCellChanged event,
and
this is satisfactory IF the user moves off of the cell before closing the
form. An obvious alternative would be to check for changes before closing
the form, but I would rather do it at the moment the cell gets changed.


Nov 21 '05 #4
Hi,

Here is a link to an article on how to detect when a row is
deleted that does not require you to create a new grid for. With Vs.Net 2005
added the datagridview as new control. It has a lot of improvements over the
datagrid.

http://www.windowsformsdatagridhelp....9-57ec163eaa17

Ken
----------------------

"Earl" wrote:
Sorry for what was somewhat of a confusing response ... basically where I'm
at right now is that the currency manager doesn't do any more than the
CurrentCellChanged event does. To trigger the currency manager, I would
still have to move out of the cell.

So I went past that, and decided to just use the OK/Close button to trigger
an update in case the user had NOT moved out of the cell. This of course
creates another issue -- what if the user had deleted a row -- with the
Delete key instead of the button? Well, I could call for a delete command
there, but then it appeared that I would have to derive a custom datagrid to
capture the delete key.

I'm tired, it's late, I've been working with this damn datagrid for going on
2 years now, and if everything has to be derived to provide basic
functionality, I'm not real sure it's worth the bother. I'm tired of working
out data relations in the grid too. I sure hope they get it right in 2005.

"Earl" <br******@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Thanks Ken. I'm already using the currency manager (with a dataview) and
while it intercepts my changes WITHIN a cell, it does not catch the Delete
key with a row selected.

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Hi,

You can use the currency managers current changed event to detect
changes.

http://www.windowsformsdatagridhelp....6-9cc458453630

Dim ds As New DataSet
Dim WithEvents cm As CurrencyManager
Dim da As OleDbDataAdapter

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim strConn As String
Dim strSQL As String
Dim conn As OleDbConnection
Dim cmd As OleDbCommandBuilder

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

da = New OleDbDataAdapter("Select * From Categories", conn)
da.Fill(ds, "Categories")
cmd = New OleDbCommandBuilder(da)

DataGrid1.DataSource = ds.Tables("Categories")

cm = CType(Me.BindingContext(DataGrid1.DataSource),
CurrencyManager)
End Sub
Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cm.CurrentChanged
Dim dt As DataTable
Try
dt = ds.Tables("Categories").GetChanges()
If dt.Rows.Count > 0 Then
da.Update(ds, "Categories")
ds.AcceptChanges()
End If
Catch
End Try
End Sub

Ken
------------------
"Earl" <br******@newsgroups.nospam> wrote in message
news:OG**************@TK2MSFTNGP15.phx.gbl...
I want to fire a database update off of a single change to a single cell
in
the datagrid. This apparently cannot be done using keypress, keyup,
keydown,
etc. I've read George Shepard's FAQ and while I may have overlooked it, I
have not found an answer. I now am using the CurrentCellChanged event,
and
this is satisfactory IF the user moves off of the cell before closing the
form. An obvious alternative would be to check for changes before closing
the form, but I would rather do it at the moment the cell gets changed.



Nov 21 '05 #5
Thanks Ken. Informative website and the handler appears to be the answer I
need.
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com...
Hi,

Here is a link to an article on how to detect when a row is
deleted that does not require you to create a new grid for. With Vs.Net
2005
added the datagridview as new control. It has a lot of improvements over
the
datagrid.

http://www.windowsformsdatagridhelp....9-57ec163eaa17

Ken
----------------------

"Earl" wrote:
Sorry for what was somewhat of a confusing response ... basically where
I'm
at right now is that the currency manager doesn't do any more than the
CurrentCellChanged event does. To trigger the currency manager, I would
still have to move out of the cell.

So I went past that, and decided to just use the OK/Close button to
trigger
an update in case the user had NOT moved out of the cell. This of course
creates another issue -- what if the user had deleted a row -- with the
Delete key instead of the button? Well, I could call for a delete command
there, but then it appeared that I would have to derive a custom datagrid
to
capture the delete key.

I'm tired, it's late, I've been working with this damn datagrid for going
on
2 years now, and if everything has to be derived to provide basic
functionality, I'm not real sure it's worth the bother. I'm tired of
working
out data relations in the grid too. I sure hope they get it right in
2005.

"Earl" <br******@newsgroups.nospam> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
> Thanks Ken. I'm already using the currency manager (with a dataview)
> and
> while it intercepts my changes WITHIN a cell, it does not catch the
> Delete
> key with a row selected.
>
> "Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
> news:uB**************@TK2MSFTNGP12.phx.gbl...
>> Hi,
>>
>> You can use the currency managers current changed event to
>> detect
>> changes.
>>
>> http://www.windowsformsdatagridhelp....6-9cc458453630
>>
>> Dim ds As New DataSet
>> Dim WithEvents cm As CurrencyManager
>> Dim da As OleDbDataAdapter
>>
>> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles MyBase.Load
>> Dim strConn As String
>> Dim strSQL As String
>> Dim conn As OleDbConnection
>> Dim cmd As OleDbCommandBuilder
>>
>> strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
>> strConn &= "Data Source = Northwind.mdb;"
>>
>> conn = New OleDbConnection(strConn)
>>
>> da = New OleDbDataAdapter("Select * From Categories", conn)
>> da.Fill(ds, "Categories")
>> cmd = New OleDbCommandBuilder(da)
>>
>> DataGrid1.DataSource = ds.Tables("Categories")
>>
>> cm = CType(Me.BindingContext(DataGrid1.DataSource),
>> CurrencyManager)
>> End Sub
>>
>>
>> Private Sub cm_CurrentChanged(ByVal sender As Object, ByVal e As
>> System.EventArgs) Handles cm.CurrentChanged
>> Dim dt As DataTable
>> Try
>> dt = ds.Tables("Categories").GetChanges()
>> If dt.Rows.Count > 0 Then
>> da.Update(ds, "Categories")
>> ds.AcceptChanges()
>> End If
>> Catch
>> End Try
>> End Sub
>>
>> Ken
>> ------------------
>> "Earl" <br******@newsgroups.nospam> wrote in message
>> news:OG**************@TK2MSFTNGP15.phx.gbl...
>> I want to fire a database update off of a single change to a single
>> cell
>> in
>> the datagrid. This apparently cannot be done using keypress, keyup,
>> keydown,
>> etc. I've read George Shepard's FAQ and while I may have overlooked
>> it, I
>> have not found an answer. I now am using the CurrentCellChanged event,
>> and
>> this is satisfactory IF the user moves off of the cell before closing
>> the
>> form. An obvious alternative would be to check for changes before
>> closing
>> the form, but I would rather do it at the moment the cell gets
>> changed.
>>
>>
>>
>
>


Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Neil | last post: by
3 posts views Thread by siaj | last post: by
2 posts views Thread by Deepesh | last post: by
2 posts views Thread by Rajani | last post: by
1 post views Thread by kevin | last post: by
reply views Thread by arlie_maija | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.