Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editing in a DataGrid - questions ?

Status
Not open for further replies.

StevenK

Programmer
Jan 5, 2001
1,294
GB
I'm making use of a dataGrid and have set it up such that only some of the columns are editable - this has been done by making use DataGridTableStyle and GridColumnStyles.
The situation I am now in is that I can edit the data (requested fields) as required.
However I now have two additional requirements I can't seem to fathom :

1). How can I determine whether my user has changed the data entries in a given row ? Is there some event I can make use of ? My application needs to know which rows have been changed through editing in the grid.

2). Given the fact that I've allowed the user to perform editing within the grid it's also opened up the ability to add new rows in the grid (I've not tested deleting). How can I prevent the addition of new rows through the grid ?

Any help would be appreciated.
Thanks in advance

Steve
 
1.) I'm not sure exactly what you mean. Do you want to know specifically what rows have been changed for some other function, or are you just trying to update the underlying database?

2.) I'm not sure in .Net how to do that. I would be interested as well, as its not as easy as datagrids in VB 6 where you have "Allow New" and that type of stuff.
 
I've resolved the 2nd question by using a DataView as the DataSource for the grid rather than a DataTable and using the 'AllowNew' + 'AllowDelete' properties.
My question 1 still stands - I want to establish whether an entry in the grid has been changed so that I can flag it as being 'edited'. Can this be done ? I'm currently working through a more complex answer to this but would obviously favour something simple. :)
Steve
 
Flag it visually in the grid, or flag it in the database? If you're just worried about the database end, you could always put a time-stamp and update it when a record is edited.

If you're talking about visually while the user is using it, do you want to do something like changing the color of the row so the user knows not to edit that row again?

What about the TextChanged event? Flag the row after that happens.
 
Scratch that, that won't work either....I'm thinkin still.
 
I'm not sure what your problem is, but I will try to answer to your question.
You could save the new row directly after the user edited it. If that's not what you want, you could have a flag for the objects you are showing that tells that the object has modified (is either new or has changed).
If you use directly a DataSet, as it seems to me to be the case, you may use a list that keeps the keys of the rows that have changed, and when you need updating just iterate through the list and do the job.
I think there are a lot of possibilities. I cannot tell you which is the best for you if I don't know how you are using the grid.
 
I've tried to make use of the TextChanged event against the grid but this does not prove useful in this case.
I'm wanting the show within the grid when something has changed (in a column that is non-editable - just a flag indicating it has been 'edited')
Currently what I've resorted to is using a DataSet, GetChanges(DataRowState.Modified) and Merge. This is done against the contents of the grid prior to posting any of the data as worked on in the grid.
Ideally I would like to indicate to the user that the row data has been edited.
Can this be done ??
Please advise.
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top