Updating cells in datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a datagrid bound to a sqlserver table. It has 2 columns. how can i write a statement that will evaluate when i change data in a cell of column 1 of the datagrid and trigger the data in column 2 to change base off of the column 1 change?
 
Chris:

YOu can trap the CurrentCellChanged event to detect a change in cell.
Inside the event handler, you can examine currentcell which will give you a
column and cell reference.

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.CurrentCellChanged

If DataGrid1.CurrentCell().ColumnNumber = 1 Then

DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) = WhateverValue

'Where 2 is the Columnnumber of the Column2 you mention in your question

End If

End Sub

Chris said:
I have a datagrid bound to a sqlserver table. It has 2 columns. how can i
write a statement that will evaluate when i change data in a cell of column
1 of the datagrid and trigger the data in column 2 to change base off of the
column 1 change?
 
Chris, if the formula is constant, you can use an expression column to do
this, then the changes will happen automatically without any intervention
on your part. Would that help?

Also, you'll know the changed value, so couldn't you use if
currentcell.Item(whatever) = Blue then dataGrid.Column2 value = 77.00?
(this is pseudo code, but the idea is the same)
Chris said:
That works great for catching the change of the cell but i need it to
evaluate the changed value and update the column 2 cell if it meets a
certain condition. I.e. if column 1 cell = blue then column 2 cell = $77.00
 
Chris:
Actually, if you can't use an expression, trapping the CurrentColumnChanged
event of the datatable should do it for you
Chris said:
That works great for catching the change of the cell but i need it to
evaluate the changed value and update the column 2 cell if it meets a
certain condition. I.e. if column 1 cell = blue then column 2 cell = $77.00
 
let me better explain what i am doing

I query a table and return 6 columns the first 5 are all null and the 6th column is a date-time field

column 1-5 represent a work week e.g M,T,W,T,

the program schedules the first date we will start bulding a product (this is column 6

the person who schedules will put a quantity in a column 1 through 5 which will represent the first day schedule

for example if he puts a 5 in the first column (Monday) then the date will change to mondays date, if the first value is in column 2 (tuesday) then the date value will be tusedays date, etc et

So what i am looking for is something that will check if column one is null and if it is go to column two and so on untill it finds the first column that has a number in it then populate the correct date accordingly. I need it to evaluate all 5 columns on any one of them changing though.

Hope this helps clarify my project
 
Let:

If that's the case, then CurrentCellChanged would appear to be the perfect
event. All you really need to do is walk through each column of a datarow,
see which one isn't null, and use that index to build your last field.
However, it seems an expression column is the way to go. Let me double
check what you are saying.

You can 6 columns, the first 5 of which refere to a day of the week
sequentially. If I upt something in the first column, then the datetime
field at the end shoudl turn to MOnday and the same for every other field.
I think nesting ISNull functions in the expression will get you there.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDataDataColumnClassExpressionTopic.asp
Then, if you use an expression column, as soon as the value is changed, the
value in the calculated column will change automatically as well.

Am I understanding this right?
let said:
let me better explain what i am doing.

I query a table and return 6 columns the first 5 are all null and the 6th column is a date-time field.

column 1-5 represent a work week e.g M,T,W,T,F

the program schedules the first date we will start bulding a product (this is column 6)

the person who schedules will put a quantity in a column 1 through 5 which
will represent the first day schedule.
for example if he puts a 5 in the first column (Monday) then the date will
change to mondays date, if the first value is in column 2 (tuesday) then the
date value will be tusedays date, etc etc
So what i am looking for is something that will check if column one is
null and if it is go to column two and so on untill it finds the first
column that has a number in it then populate the correct date accordingly. I
need it to evaluate all 5 columns on any one of them changing though.
 
yes, I believe that is correct. I am not sure how to use an expression field and i understand isdbnull but not how to referencer the datgrid item in the nested isdbnull function.
 
This link should help you. You just use ISNULL() again in the second part
of the first isnull statement which takes two parameters. One for each day.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemDataDataColumnClassExpressionTopic.asp
ISNULL(Monday, ISNULL(Tuesday, ISNULL(etc)))
chris said:
yes, I believe that is correct. I am not sure how to use an expression
field and i understand isdbnull but not how to referencer the datgrid item
in the nested isdbnull function.
 
The HTML is probably cutting off in Outlook express. Copy the line
underneat the hyperlink and you should be good to go. Or just put
DataColumn.Expression in Google and check out the MSDN link.
 
Back
Top