473,289 Members | 1,884 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,289 software developers and data experts.

Datagrid cell change event? Where to find event.

I have a datagrid and would like to know what even fires when a cell is
changed?

I want to know when the user changes a cell and moves to the next. I have
some code that needs to be done to make sure entry is valid?
Thanks,

Rog
Nov 21 '05 #1
4 10656


copied from one of my projects

Private Sub dgModel_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgModel.CurrentCellChanged

dgStyleSelection(dgModel, dgModel.CurrentCell.RowNumber())

End Sub
so you use the "CurrentCellChanged" event (this fires by mouse and
keyboard )

M. Posseth

"Roger" <da*****@netins.net> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
I have a datagrid and would like to know what even fires when a cell is
changed?

I want to know when the user changes a cell and moves to the next. I have
some code that needs to be done to make sure entry is valid?
Thanks,

Rog

Nov 21 '05 #2
M,

This shows me that the cell changed, but gives me the new coordinates not
the current coordinates. I would like to validate the data entered into the
cell before leaving.

Roger
"M. Posseth" <mi*****@nohausystems.nl> wrote in message
news:d2**********@reader10.wxs.nl...


copied from one of my projects

Private Sub dgModel_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgModel.CurrentCellChanged

dgStyleSelection(dgModel, dgModel.CurrentCell.RowNumber())

End Sub
so you use the "CurrentCellChanged" event (this fires by mouse and
keyboard )

M. Posseth

"Roger" <da*****@netins.net> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
I have a datagrid and would like to know what even fires when a cell is
changed?

I want to know when the user changes a cell and moves to the next. I have some code that needs to be done to make sure entry is valid?
Thanks,

Rog


Nov 21 '05 #3
Roger,

I think, that you can use a datagridtextbox in a datagridtextboxcolumn.
From that you can than use the validating event.

I never used it in this way.

A sample I once made with a tooltip
\\\
Private WithEvents dtbCol1 As DataGridTextBox
Private ToolTip1 As New ToolTip
')
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Datagrid1.ReadOnly = True
Dim ts As New DataGridTableStyle
ts.MappingName = ds.Tables(0).TableName
Dim column As New DataGridTextBoxColumn
ts.GridColumnStyles.Add(column)
DataGrid1.TableStyles.Add(ts)
column = DirectCast(ts.GridColumnStyles(0), DataGridTextBoxColumn)
dtbCol1 = DirectCast(column.TextBox, DataGridTextBox)
column.MappingName = ds.Tables(0).Columns(0).ColumnName
column.HeaderText = "Cor"
column.Width = 30
dv = New DataView(ds.Tables(0))
dv.AllowNew = False
DataGrid1.DataSource = dv
End Sub
Private Sub dtbCol1_ToolTip(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles dtbCol1.MouseEnter
ToolTip1.SetToolTip(DirectCast(sender, DataGridTextBox), _
"Row: " & DataGrid1.CurrentRowIndex + 1)
End Sub
///

I hope this helps,

Cor
Nov 21 '05 #4
aha

well you could declare a static variabel and read the previous cell values
with it ( i am famous for my simplistic solutions :-) )

or

There are two types of input validation available for the Windows Forms
DataGrid control. If the user attempts to enter a value that is of an
unacceptable data type for the cell, for example a string into an integer,
the new invalid value is replaced with the old value. This kind of input
validation is done automatically and cannot be customized.
The other type of input validation can be used to reject any unacceptable
data, for example a zero value in a field that must be greater than or equal
to one, or an inappropriate string. This is done in the dataset by writing
an event handler for the DataTable.ColumnChanging or DataTable.RowChanging
event. The example below uses the ColumnChanging event because the
unacceptable value is disallowed for the "Product" column in particular. You
might use the RowChanging event for checking that the value of an "End Date"
column is later than the "Start Date" column in the same row.

Private Sub Customers_ColumnChanging(ByVal sender As Object, _
ByVal e As System.Data.DataColumnChangeEventArgs)
' Only check for errors in the Product column
If (e.Column.ColumnName.Equals("Product")) Then
' Do not allow "Automobile" as a product.
If CType(e.ProposedValue, String) = "Automobile" Then
Dim badValue As Object = e.ProposedValue
e.ProposedValue = "Bad Data"
e.Row.RowError = "The Product column contians an error"
e.Row.SetColumnError(e.Column, "Product cannot be " & _
CType(badValue, String))
End If
End If
End Sub
' Assumes the grid is bound to a dataset called customersDataSet1
' with a table called Customers.
' Put this code in the form's Load event or its constructor.
AddHandler customersDataSet1.Tables("Customers").ColumnChangi ng, AddressOf
Customers_ColumnChanging

i hope this answers your problem

happy coding :-)

Michel Posseth [MCP]


"Roger" <da*****@netins.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
M,

This shows me that the cell changed, but gives me the new coordinates not
the current coordinates. I would like to validate the data entered into the cell before leaving.

Roger
"M. Posseth" <mi*****@nohausystems.nl> wrote in message
news:d2**********@reader10.wxs.nl...


copied from one of my projects

Private Sub dgModel_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles dgModel.CurrentCellChanged

dgStyleSelection(dgModel, dgModel.CurrentCell.RowNumber())

End Sub
so you use the "CurrentCellChanged" event (this fires by mouse and
keyboard )

M. Posseth

"Roger" <da*****@netins.net> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
I have a datagrid and would like to know what even fires when a cell is changed?

I want to know when the user changes a cell and moves to the next. I

have some code that needs to be done to make sure entry is valid?
Thanks,

Rog



Nov 21 '05 #5

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

Similar topics

1
by: Lester Moreno | last post by:
Hello all, I'm trying to find a way to get a event raised when you change some text on a DataGrid Cell, I need to be able to search in another table what the user typed on that cell. I found...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
3
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case...
4
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
2
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
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...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Greetings, I am trying to find out how to do something that on the surface seems like it should be very simple to do. I have a datagrid with a datatable bound to it using the SetDataBinding...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.