473,654 Members | 3,239 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3336
i suppose you use a DataTable as datasource
check the events of your datatable...
ColumnChanging and ColumnChanged for example...

"Steve" <sf*****@flinti nd-remove.com> wrote in message
news:eM******** ******@tk2msftn gp13.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*****@flinti nd-remove.com> wrote in message
news:eM******** ******@tk2msftn gp13.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
"myDataGridColu mnStyle.TextBox .Validating" event. I believe you could also
handle the myDataGridColum nStyle.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 myDataGridColum nStyle.TextBox. Validating, AddressOf
myValidatingHan dler
///

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

jim

"Steve" <sf*****@flinti nd-remove.com> wrote in message
news:eM******** ******@tk2msftn gp13.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 DataGridTableSt yle
DataGrid1.DataS ource = DS1
DataGrid1.DataM ember = "rooms"
ts = New DataGridTableSt yle
ts.MappingName = "rooms"
ts.PreferredRow Height = 25
ts.AlternatingB ackColor = System.Drawing. Color.Gainsboro
ts.HeaderBackCo lor = System.Drawing. Color.Gainsboro
ts.HeaderForeCo lor = System.Drawing. Color.Black

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

Dim tb1 As DataGridTextBox Column
tb1 = New DataGridTextBox Column
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnSt yles.Add(tb1)

Dim tb2 As DataGridTextBox Column
tb2 = New DataGridTextBox Column
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnSt yles.Add(tb2)
DataGrid1.Table Styles.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******** ******@TK2MSFTN GP09.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
"myDataGridColu mnStyle.TextBox .Validating" event. I believe you could also
handle the myDataGridColum nStyle.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 myDataGridColum nStyle.TextBox. Validating, AddressOf
myValidatingHan dler
///

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

jim

"Steve" <sf*****@flinti nd-remove.com> wrote in message
news:eM******** ******@tk2msftn gp13.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
DataGridColumnS tyle.TextBox.Va lidating (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.Val idating, me.myValidating Procedure
///

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 myValidatingPro cedure(byval sender as object, byval e as
System.Componen tModel.EventArg s)

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*****@flinti nd-remove.com> wrote in message
news:%2******** ********@tk2msf tngp13.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 DataGridTableSt yle
DataGrid1.DataS ource = DS1
DataGrid1.DataM ember = "rooms"
ts = New DataGridTableSt yle
ts.MappingName = "rooms"
ts.PreferredRow Height = 25
ts.AlternatingB ackColor = System.Drawing. Color.Gainsboro
ts.HeaderBackCo lor = System.Drawing. Color.Gainsboro
ts.HeaderForeCo lor = System.Drawing. Color.Black

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

Dim tb1 As DataGridTextBox Column
tb1 = New DataGridTextBox Column
tb1.HeaderText = "Room Number"
tb1.MappingName = "roomno"
tb1.NullText = ""
tb1.Width = 150
ts.GridColumnSt yles.Add(tb1)

Dim tb2 As DataGridTextBox Column
tb2 = New DataGridTextBox Column
tb2.HeaderText = "Room Description"
tb2.MappingName = "roomdesc"
tb2.NullText = ""
tb2.Width = 350
ts.GridColumnSt yles.Add(tb2)
DataGrid1.Table Styles.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******** ******@TK2MSFTN GP09.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
"myDataGridColu mnStyle.TextBox .Validating" event. I believe you could also
handle the myDataGridColum nStyle.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 myDataGridColum nStyle.TextBox. Validating, AddressOf
myValidatingHan dler
///

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

jim

"Steve" <sf*****@flinti nd-remove.com> wrote in message
news:eM******** ******@tk2msftn gp13.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
3171
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 text. Before changing to another cell in the DataGrid, I move my mouse pointer off the DataGrid and change the selected item in a ListBox or TreeView. Here's my question Which should fire first, the DataTable's RowChanged/CellChanged event or...
6
1706
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 I tell that the user has reselected a different set of rows in a datagrid.
2
17002
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 the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
7
1996
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 display all of the information. I now have a need to drop this datagrid into a repeater on "Page 2". The repeater will grab ALL orders within a given date range and output the datagrids for each order. Remember, the Page 1 is built to display one...
4
2115
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 Datagrid in a Web Custom Control (WCC) : The datagrid has LinkButton Column which has a select LinkButton for each row. When this button is clicked, the Datagrid raises its 'ItemCommand' event which captures the information for that row and...
2
270
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
1574
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 PageIndexChanged of the datagrid 'coz every time when the user change of page the app load again all data and another processes with the data even though I have load one dataset with the data for the datagrid..... the question is? What can I do to...
13
2472
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 them. In a plain vanilla DataGrid, when you click on the RowHeader, the appropriate row changes colors. I ASSUME this should be done in the Paint (or PaintText) override of the DataGridColumnStyle in question. My problem is that I don't know...
13
2445
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 works best) to display a dropdown menu of fields populated from table tblInvoiceData. This control also includes a textbox which the user can input a value. These two columns are side by side and not in a vertical layout. The user then clicks on...
10
2957
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 22222 D E F 33333 G H I 44444 J K L
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7309
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.