Two datagrid Q's

agroom

Active member
Joined
Sep 14, 2006
Messages
39
Programming Experience
Beginner
1) How do I display a calculated value in an unbound datagridview column? I know I can make a script to cycle though the rows and do the calculations, but there's hundreds of records and multiple searches and filters the user can perform and doing that calculation evertime sounds like a lot of un-necessary work.

2) How do I set the focus to a specific cell. Not just highlighted, but insert the cursor.

Thanks in advance everyone!
 
1) How do I display a calculated value in an unbound datagridview column? I know I can make a script to cycle though the rows and do the calculations, but there's hundreds of records and multiple searches and filters the user can perform and doing that calculation evertime sounds like a lot of un-necessary work.

The underlying datatable that provides the DG with data, can have columns that are composed from other columns, via the Expression property.

For example, if you had a datatable of 2 columns, both filled with numbers, adding a third column and setting its expression to col1 + col2 should "fill" it with values that are the sumamtion of the other two columns. For more information, see http://msdn.microsoft.com/library/d...fsystemdatadatacolumnclassexpressiontopic.asp

2) How do I set the focus to a specific cell. Not just highlighted, but insert the cursor.
I'm not sure what you mean; do you wish to invoke the editing of a specific cell? e.g. click a button and cell 2,2 changes appearance from a label to an editable textbox? (as it would if you twice-clicked it)
 
cjard said:
The underlying datatable that provides the DG with data, can have columns that are composed from other columns, via the Expression property.
For more information, see http://msdn.microsoft.com/library/d...fsystemdatadatacolumnclassexpressiontopic.asp

Perfect! This is the expression I used.

Me.LogBookDataSet.Tables("tblLogFile").Columns("fldManHours").Expression = "fldBudget / 75"


cjard said:
I'm not sure what you mean; do you wish to invoke the editing of a specific cell? e.g. click a button and cell 2,2 changes appearance from a label to an editable textbox? (as it would if you twice-clicked it)

Here's the issue. I'm working with a user on the app I'm developing and he's concered that when a new row is entered (last column is filled in), the user tabs moving focus the next blank row, then decides to click save, the focus is then moved back up to the row they just entered. Someone not paying attention might then start entering data for the next row, not knowing the focus has changed, and overwrite existing data.

What I'm looking to do is after saving, move focus to the next blank row so if they start typing it'll go into the new row. Now, I don't want a new row added yet because if that's the last row they plan to enter the program will error having a blank new row.

However, before a new row is added you can manuall set the row focus to that blank row without actually starting a new row until the user begins typing. This is what I want to accomplish.


btw - I've come here quite often over the past few months looking for assistance and you've always been there to lend a helping hand! Really appreciated!
 
Well.. I say let em carry on typing! It's possible to take the row they typed out, be it a properly added one or an accidentally overtyped one..

If its added it will have arow state as such
If its an overwritten it will have a rowstate of Modified, and can be found using:

dt as DataTable = mainTable.GetCHanges(DataRowState.Modified)


You can then turn it into an added row.. i forget exactly how, something like dt.Rows(0).SetAdded() and it turns it into an added row - which will be sent to the DB using the INSERT cdommand

additionally you can turn of fhte user ability to add rows to the grid (set DataGridView.AllowUserToAddRows = false) and then make them use a key combo or click an add button to add a row.

Basically, find some way to turn of fthe potential flaw route and break up the path through the problem domain to ensure that the correct result is achieved ;)
 
Back
Top