PC Review


Reply
Thread Tools Rate Thread

Datagrid cell change event? Where to find event.

 
 
Roger
Guest
Posts: n/a
 
      29th Mar 2005
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


 
Reply With Quote
 
 
 
 
M. Posseth
Guest
Posts: n/a
 
      29th Mar 2005


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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Roger
Guest
Posts: n/a
 
      29th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:d2c5gh$ao3$(E-Mail Removed)...
>
>
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      29th Mar 2005
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


 
Reply With Quote
 
M. Posseth
Guest
Posts: n/a
 
      29th Mar 2005
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").ColumnChanging, AddressOf
Customers_ColumnChanging

i hope this answers your problem

happy coding :-)



Michel Posseth [MCP]




"Roger" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:d2c5gh$ao3$(E-Mail Removed)...
> >
> >
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
apply cell change event to single column - WorksheetChange Event MiataDiablo@gmail.com Microsoft Excel Programming 5 4th May 2008 02:28 AM
Row change event in datagrid? Wongalogic Microsoft Dot NET Framework Forms 1 23rd Apr 2006 09:42 AM
Key Event in DataGrid Cell - for experts =?Utf-8?B?R2lkaQ==?= Microsoft C# .NET 0 17th Apr 2006 10:29 PM
Win Form datagrid row change event?? djam Microsoft C# .NET 1 11th Mar 2005 02:32 PM
Event on Editing a Cell of a DataGrid? =?Utf-8?B?bmlldXJpZw==?= Microsoft Dot NET Framework Forms 0 7th Feb 2005 01:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:56 AM.