472,958 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

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 3297
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
6
by: BBFrost | last post by:
I'm using Net 1.1 (2003) SP1 & Windows 2000 Here's the issue ... Rows 12 thru 24 are selected in a datagrid. The user now unselects rows 12 thru 24 and selects rows 45 thru 70 ??? How can...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
7
by: Scott Schluer | last post by:
Hi All, I have a functioning datagrid on "Page 1" that displays order information for a single order (this is for an e-commerce site). It's actually a combination of a couple datagrids to...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
2
by: John McCarthy | last post by:
Question: I would like to add a ButtonColumn to a datagrid on the fly ..... Thus far .... (1) Adding the button works .... (2) Trying to hook up an event
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
10
by: amiga500 | last post by:
Hello, I have one basic simple question. When I have multiple records in the datagrid as follows: Code Product 1 Product 2 Product 3 11111 A B C...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.