473,698 Members | 1,947 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

value change in datagrid

Hello,
How can I trigger an event, when a value (cell) in my datagrid changes?
TIA,
amber
Jul 21 '05 #1
8 7842
There's a CurrentCellChan ged event which should do it for you.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"amber" <am***@discussi ons.microsoft.c om> wrote in message
news:08******** *************** ***********@mic rosoft.com...
Hello,
How can I trigger an event, when a value (cell) in my datagrid changes?
TIA,
amber

Jul 21 '05 #2
hey - that event is when you change cells in the grid, not for when you change the contents of a cell ... I'll post back when I get what she wants, I want the same thing just now.

--
Message posted via http://www.dotnetmonster.com
Jul 21 '05 #3
Yes Todd you're right. And that's one very easy way to check if something
has changed or not. There are a few ways to go about getting the
values -but remember that when you start changing something, the changes
aren't finsihed until the current edit is ended. That's why if you're
typing something in a cell who's column is sorted, it doesn't start sorting
as you type - it's only when you are done editing that the value will get
sorted -so is it here.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Todd Harvey via DotNetMonster.c om" <fo***@DotNetMo nster.com> wrote in
message news:78******** *************** *******@DotNetM onster.com...
hey - that event is when you change cells in the grid, not for when you change the contents of a cell ... I'll post back when I get what she wants,
I want the same thing just now.
--
Message posted via http://www.dotnetmonster.com

Jul 21 '05 #4
Amber - after reading Todd's post I realized that my post may have been
confusing. YOu can use CurrentCellChan ged to determine when you have moved
to another cell. Based on the way editing in a grid works - the edit
doesn't take until endcurrentedit. Depending on what you ultimately want to
do -there are a few different approaches. RowChanging on the underlying
datatable is another way to make that determination

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"amber" <am***@discussi ons.microsoft.c om> wrote in message
news:08******** *************** ***********@mic rosoft.com...
Hello,
How can I trigger an event, when a value (cell) in my datagrid changes?
TIA,
amber

Jul 21 '05 #5
Thanks,
What I'm actually trying to do is set a variable ('isDirty') to true, if the
value in any cell in my datagrid changes.
Maybe I'm going about this in the wrong way?
Amber

Jul 21 '05 #6
An easy way to do this is to check the underlying DataSet's HasChanges
property - this way regardless of how the data gets changed, you can
recognize it.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"amber" <am***@discussi ons.microsoft.c om> wrote in message
news:CA******** *************** ***********@mic rosoft.com...
Thanks,
What I'm actually trying to do is set a variable ('isDirty') to true, if the value in any cell in my datagrid changes.
Maybe I'm going about this in the wrong way?
Amber

Jul 21 '05 #7
you guys are super active on this board! you've got like 5 responses since yesterday afternoon on this

I actually got to work what Amber's original request was - I got the OnChange to fire for the underlying text box control that is in the control array of the datagrid. And if that's not confusing, it probably should be.

When I changed a text box - or when I typed anything into my text box, it fired my little OnChange for every single character typed in, which IMHO became an almost useless event handler, and I started to re-consider W.G.Ryan's original response (and to regret my response, and to hope that he didn't start a flame war on me). The OnCellChanged is probably the best place to handle a change to the data.

Here's a brief snippet from MSDN:
Private Sub DataGrid1_Curre ntCellChanged(B yVal sender As Object, ByVal e As System.EventArg s) Handles DataGrid1.Curre ntCellChanged
Dim myString As String = "CurrentCellCha nged event raised, cell focus is at "
' Get the co-ordinates of the focussed cell.
Dim myPoint As String = DataGrid1.Curre ntCell.ColumnNu mber.ToString() + "," + DataGrid1.Curre ntCell.RowNumbe r.ToString()
' Create the alert message.
myString = myString + "(" + myPoint + ")"
' Show Co-ordinates when CurrentCellChan ged event is raised.
MessageBox.Show (myString, "Current cell co-ordinates")

End Sub

---------------
Here's the ugly thing to associate an event with the underlying control:
' how to add the event listener for all the text boxes?
For i As Integer = 0 To Me.dgEquipment. Controls.Count - 1
Dim ctl As System.Windows. Forms.Control = Me.dgEquipment. Controls.Item(i )
System.Console. Write(ctl.GetTy pe().Name)
System.Console. Write(" ")
System.Console. Write(ctl.Text)
System.Console. WriteLine("")
If (ctl.GetType(). Name = "DataGridTextBo x") Then
AddHandler ctl.TextChanged , AddressOf txtQuantity_Nul lTextChanged
'OnTextChanged
End If
Next
Private Sub txtQuantity_Nul lTextChanged(By Val sender As Object, ByVal e As System.EventArg s) Handles txtQuantity.Nul lTextChanged
System.Windows. Forms.MessageBo x.Show(" changed ")
End Sub

I gave up on this approach in favor of W.G.Ryan's ... but you could associate any event you wanted, I suppose. And you could associate it only with certain columns, if you wanted.

This thread is turning out to be fruitful for me (I didn't know about the IsDirty thing , getting to the underlying controls was handy, and in the course of this I found some really cool stuff about putting all kinds of user controls in the data grid: http://www.codeproject.com/cs/miscct...asp#xx983919xx (and their associated events)

But it is funny that while I did what Amber said she wanted, I didn't like it.
W.G.Ryan answered what she didn't ask, and I'm using it.
Amber actually meant something other than what she said, W.G. took care of that too, and it helped everybody.
And maybe more.

--
Message posted via http://www.dotnetmonster.com
Jul 21 '05 #8
I have spent way too much time on this, but I have a grid with
Unit Price, Quantity, Cost, and I want it to automatically update
cost = price * quantity
as the user enters quantity.

I have it working.

It is extremely ugly (I capture events for grid controls, I grab the text box I'm entering into, and anyway, it works.)
Perhaps if it were not a bound grid, it would be easier. Message me if you are interested. todd_harvey@A_* @tennessee.edu

--
Message posted via http://www.dotnetmonster.com
Jul 21 '05 #9

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

Similar topics

1
15743
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I have a problem with capturing the changed value of a text box in a datagrid. The datagrid is populated based on a dataset and I am using template columns to show some of the columns. Few of the columns have textboxes to make them available for editing. I am trying to update the dataset all at once using one update button. Here is my code... (for simplicity I have only listed one of the...
3
2209
by: Brett Hargreaves | last post by:
Hi, I'm having trouble with the datagrid update command. I have a datagrid called grid that poulates itself with data in the page load event. When I click the edit button it takes me into edit mode no pronlem, however when I change the data in the edit cell it is not picking up the newly typed value, it passes back the original value. eg, the orgincal value is
4
3478
by: kscdavefl | last post by:
I ahve a datagrid on a web form. I need to change the value in column 3 as follows. If the value in column 3 reads 0, I want to change it to read YES. How can I accomplish this task. Thanks, Dave
0
2651
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the CompanyName, ContactName, and ContactTitle columns from the Customers table in the Northwind database. Whenever the value of ContactTitle equals "Owner" we will change the font color to red. We can do this by using an ItemTemplate where we have...
3
1669
by: ALPO | last post by:
We have a datagrid built using template columns. Many are text boxes. These text boxes are bound to a datasource as follows: <ItemTemplate> <asp:TextBox id="txtPeriod1" runat="server" columns="1" Font-Size="8pt" text='<%# Container.dataitem ("LaborHoursAm")%>' >
1
1864
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I have a problem with capturing the changed value of a text box in a datagrid. The datagrid is populated based on a dataset and I am using template columns to show some of the columns. Few of the columns have textboxes to make them available for editing. I am trying to update the dataset all at once using one update button. Here is my code... (for simplicity I have only listed one of the...
2
12590
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's first column is a textbox(TemplateColumn), the other 3 columns are just display(BoundColumn). (1) if the value of the textbox is 0, then i'd like to change it null, so the box is empty
3
2129
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as TableCell; DataGridItem item = cell.Parent as DataGridItem; int index = item.ItemIndex;
2
2251
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? "Curtis" <curtsfakeguy@hotmail.com> wrote in message
2
2940
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 method. What I am trying to accomplish is to detect if a value has changed in any cell so that if a user closes the form without saving first, I want to prompt to save changes. I don't want to prompt if there were no changes.
0
8671
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8598
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
9152
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
8887
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
8856
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7709
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
3037
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
2
2321
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.