468,512 Members | 1,337 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DataGrid event question

I have a datagrid in a WinForm.
When the user edits an entry in the datagrid, after he leaves that field, I
would like to do some cheking. What event fires when the user does that?

I need to make sure that the value he modified does not create a dup value
in my DB.

Thank you for your help,

Steve
Nov 20 '05 #1
5 3175
i suppose you use a DataTable as datasource
check the events of your datatable...
ColumnChanging and ColumnChanged for example...

"Steve" <sf*****@flintind-remove.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
I have a datagrid in a WinForm.
When the user edits an entry in the datagrid, after he leaves that field, I would like to do some cheking. What event fires when the user does that?

I need to make sure that the value he modified does not create a dup value
in my DB.

Thank you for your help,

Steve

Nov 20 '05 #2
Hi,

http://www.syncfusion.com/FAQ/WinFor...c44c.asp#q773q

Ken
-----------------------
"Steve" <sf*****@flintind-remove.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
I have a datagrid in a WinForm.
When the user edits an entry in the datagrid, after he leaves that field,
I
would like to do some cheking. What event fires when the user does that?

I need to make sure that the value he modified does not create a dup value
in my DB.

Thank you for your help,

Steve

Nov 20 '05 #3
jim
Hi Steve,

if you create a table style and a subsequent columnstyle for each column to
be displayed in your grid then you can handle the
"myDataGridColumnStyle.TextBox.Validating" event. I believe you could also
handle the myDataGridColumnStyle.TextBox.LostFocus event, but the validating
event may be more appropriate for what you're specifically doing.

I'm handling this in one of my applications and it works nicely. You'll have
to manually add the handler to the control using the AddHandler statement.
i.e.

in form load or wherever it makes sense for you...

\\\
AddHandler myDataGridColumnStyle.TextBox.Validating, AddressOf
myValidatingHandler
///

if you need further details don't hesitate to ask.

jim

"Steve" <sf*****@flintind-remove.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
I have a datagrid in a WinForm.
When the user edits an entry in the datagrid, after he leaves that field, I would like to do some cheking. What event fires when the user does that?

I need to make sure that the value he modified does not create a dup value
in my DB.

Thank you for your help,

Steve

Nov 20 '05 #4
Thanks everybody for the many replies. I am including the code I use to
create my very simple datagrid. I am only concerned about the first column,
when the user changes it.

'------DataGrid1 TABLESTYLE----------------------

Dim ts As DataGridTableStyle
DataGrid1.DataSource = DS1
DataGrid1.DataMember = "rooms"
ts = New DataGridTableStyle
ts.MappingName = "rooms"
ts.PreferredRowHeight = 25
ts.AlternatingBackColor = System.Drawing.Color.Gainsboro
ts.HeaderBackColor = System.Drawing.Color.Gainsboro
ts.HeaderForeColor = System.Drawing.Color.Black

'-------dg_punch COLUMNSTYLES----------------------

Dim tb1 As DataGridTextBoxColumn
tb1 = New DataGridTextBoxColumn
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnStyles.Add(tb1)

Dim tb2 As DataGridTextBoxColumn
tb2 = New DataGridTextBoxColumn
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnStyles.Add(tb2)
DataGrid1.TableStyles.Add(ts)
So, what would my code look like to do the validating? I am fairly new to
VB.NET and have not created a 'handler' yet. I would appreciate any
information.

Thanks again,

Steve

"jim" <james_matthews_at_shi_dotcom> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
Hi Steve,

if you create a table style and a subsequent columnstyle for each column to be displayed in your grid then you can handle the
"myDataGridColumnStyle.TextBox.Validating" event. I believe you could also
handle the myDataGridColumnStyle.TextBox.LostFocus event, but the validating event may be more appropriate for what you're specifically doing.

I'm handling this in one of my applications and it works nicely. You'll have to manually add the handler to the control using the AddHandler statement.
i.e.

in form load or wherever it makes sense for you...

\\\
AddHandler myDataGridColumnStyle.TextBox.Validating, AddressOf
myValidatingHandler
///

if you need further details don't hesitate to ask.

jim

"Steve" <sf*****@flintind-remove.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
I have a datagrid in a WinForm.
When the user edits an entry in the datagrid, after he leaves that field,
I
would like to do some cheking. What event fires when the user does that?

I need to make sure that the value he modified does not create a dup

value in my DB.

Thank you for your help,

Steve


Nov 20 '05 #5
jim
Hi Steve,

thinking about this issue a little further, i think your specific situation
should be handled by creating a unique constraint in the database itself. I
would especially not recommend validating duplicate db values at the ui
layer. you may want to check your design before moving forward.

as far as handling the datagrid events though...

you would create a handler for whichever event you wanted to catch. since
you seem to want to validate the data in the gridcell i would recommend the
DataGridColumnStyle.TextBox.Validating (you won't find this in intellisense,
but keep typing, it's there) event for this. Just my personal preference,
there are other ways such as suggested. by George Shepards winforms faq.

in your form load you could add some code like this...

\\\
AddHandler tb1.TextBox.Validating, me.myValidatingProcedure
///

the addhandler statement points the event to the actual procedure that will
perform the validation for you. Keep in mind that this procedure must
receive in the same parameters that the event is passing when raised.

\\\
private sub myValidatingProcedure(byval sender as object, byval e as
System.ComponentModel.EventArgs)

dim entryIsValid as boolean = 'code to validate what is is you need to
validate here...

if (not entryIsValid)
e.Cancel 'this line invalidates the control and causes focus to
return the focus
end if

end sub
///

hope this helps,

jim

"Steve" <sf*****@flintind-remove.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Thanks everybody for the many replies. I am including the code I use to
create my very simple datagrid. I am only concerned about the first column, when the user changes it.

'------DataGrid1 TABLESTYLE----------------------

Dim ts As DataGridTableStyle
DataGrid1.DataSource = DS1
DataGrid1.DataMember = "rooms"
ts = New DataGridTableStyle
ts.MappingName = "rooms"
ts.PreferredRowHeight = 25
ts.AlternatingBackColor = System.Drawing.Color.Gainsboro
ts.HeaderBackColor = System.Drawing.Color.Gainsboro
ts.HeaderForeColor = System.Drawing.Color.Black

'-------dg_punch COLUMNSTYLES----------------------

Dim tb1 As DataGridTextBoxColumn
tb1 = New DataGridTextBoxColumn
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnStyles.Add(tb1)

Dim tb2 As DataGridTextBoxColumn
tb2 = New DataGridTextBoxColumn
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnStyles.Add(tb2)
DataGrid1.TableStyles.Add(ts)
So, what would my code look like to do the validating? I am fairly new to
VB.NET and have not created a 'handler' yet. I would appreciate any
information.

Thanks again,

Steve

"jim" <james_matthews_at_shi_dotcom> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
Hi Steve,

if you create a table style and a subsequent columnstyle for each column

to
be displayed in your grid then you can handle the
"myDataGridColumnStyle.TextBox.Validating" event. I believe you could also
handle the myDataGridColumnStyle.TextBox.LostFocus event, but the

validating
event may be more appropriate for what you're specifically doing.

I'm handling this in one of my applications and it works nicely. You'll

have
to manually add the handler to the control using the AddHandler statement. i.e.

in form load or wherever it makes sense for you...

\\\
AddHandler myDataGridColumnStyle.TextBox.Validating, AddressOf
myValidatingHandler
///

if you need further details don't hesitate to ask.

jim

"Steve" <sf*****@flintind-remove.com> wrote in message
news:eM**************@tk2msftngp13.phx.gbl...
I have a datagrid in a WinForm.
When the user edits an entry in the datagrid, after he leaves that

field,
I
would like to do some cheking. What event fires when the user does that?
I need to make sure that the value he modified does not create a dup

value in my DB.

Thank you for your help,

Steve



Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Emerson | last post: by
7 posts views Thread by Scott Schluer | last post: by
4 posts views Thread by The Alchemist | last post: by
2 posts views Thread by John McCarthy | last post: by
3 posts views Thread by Danky | last post: by
13 posts views Thread by pmcguire | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.