-- Edit 3 --- LATEST reply:I guess I **could** track the keyDown in the Grid ... if's "DEL" button, then mark the _project ( CSLA class, editableRoot ) as deleted ... and then always use the SAVE button to triggers the changes ??But that CANNOT be the best way ... I need to be able to codeBehind the "delete event" of the Grid or actually it should notify the CSLA datasource to delete itself when pushing the "DEL" button ... at least the entry is deleted from the Grid, so that's the supposed behaviour I guessPlease help-------------------------------------------
--Edit 2 ---
Normal 0 21 false false false IS X-NONE X-NONE MicrosoftInternetExplorer4
…now doing it with a button outside of the UltraGrid … kind of sucks, but works L
private void _btnDelete_Click(object sender, EventArgs e)
{
Core.Project.DeleteProject(_project.ProjectID);
_projectBindingSource.DataSource = null; //just to clear the Grid
//also clear the combo that selects projects:
Core.ProjectNameValueList.InvalidateCache();
_ucProjectsNameValue.SelectedRow = null;
_projectNameValueList = Core.ProjectNameValueList.GetAll();
_projectNameValueListBindingSource.DataSource = _projectNameValueList;
}
I would much rather be able to hit "DEL" on the keyboard and not only make the Grid delete the row in the grid, but also make the delete call to the CSLA object !
------
--- EDIT ----
I found out how to delete with a BUTTON, but I want to use the "DEL" button on the keyboard for deletion, how would I do that ? I've already managed to do it like this with a button:
private void _btnDelete_Click(object sender, EventArgs e) { //_projectBindingSource.EndEdit(); Core.Project.DeleteProject(_project.ProjectID); //_projectBindingSource.DataSource = _project; //FillProjectsDropDown(); //in case name of some project has changed }
----------------------------------------
Hi there!
Do you think of any possible reason my BindingSource which is bound against a EditableRoot, does not respond to the DEL ( button on keyboard ) for deleting my databound object ? ( The grid warns me that I'm going to delete the selected record, and when I press yes it's removed from the GRID, but nothing is called in my CSLA object ).
The update works very well ( there's no insert as this is an EditableRoot ), in the GRID and into the DataPortal_Update ...and hence gets updated successfully in the database as well.
Is there anything special I need to implement so the CSLA object will delete itself in ? I'm using the CodeSmith templates against CSLA v3.8.1 ( I have found Codesmith excellent for generating the CSLA objects by the way! ).
is there any possible way for me to attach the CSLA class to this forum ? I'll paste a couple of lines ..There's also nothing done in my Child ( EditableChild ) when I hit update/delete/insert- it's only updated/deleted/inserted inside the grid ... but never called to the CSLA classes
This code is never entered when pushing the DEL button in the Grid ... and hence there's no deletion
The Databinding in the GUI:public RecoveryUI() { InitializeComponent(); //Fills the Grid: FillProjectsDropDown(); // This will load the parent and children into the Grid, databinded successfully }
private void FillGridWithSelectedProject(int projectId) { /*_projectList = Core.ProjectList.GetByProjectID(projectId); projectListBindingSource.DataSource = _projectList;*/
_project = Core.Project.GetByProjectID(projectId); _projectBindingSource.DataSource = _project; }
public static void DeleteProject(System.Int32 projectID) { DataPortal.Delete(new ProjectCriteria {ProjectID = projectID}); }
[Transactional(TransactionalTypes.TransactionScope)] protected override void DataPortal_DeleteSelf() { bool cancel = false; OnSelfDeleting(ref cancel); if (cancel) return; DataPortal_Delete(new ProjectCriteria (ProjectID)); OnSelfDeleted(); }
[Transactional(TransactionalTypes.TransactionScope)] protected void DataPortal_Delete(ProjectCriteria criteria) { bool cancel = false; OnDeleting(criteria, ref cancel); if (cancel) return;
using (SqlConnection connection = new SqlConnection(ADOHelper.ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("[dbo].[rp_Project_Delete]", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
//result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. int result = command.ExecuteNonQuery(); if (result == 0) throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute."); } }
OnDeleted(); }
Thank you,EE
----
I just want to clarify that I'm using the standard System.Windows.Forms.BindingSource against the CSLA object
and the GUI is still very simple - it's simply done by this:
public partial class RecoveryUI : Form { //Core.ProjectList _projectList; Core.Project _project; Core.ProjectNameValueList _projectNameValueList; int _selectedProjectId; public RecoveryUI() { InitializeComponent(); //Fills the Grid: FillProjectsDropDown(); } private void FillGridWithSelectedProject(int projectId) { /*_projectList = Core.ProjectList.GetByProjectID(projectId); projectListBindingSource.DataSource = _projectList;*/ _project = Core.Project.GetByProjectID(projectId); _projectBindingSource.DataSource = _project; } private void FillProjectsDropDown() { if( _projectNameValueList != null ) { if (_projectNameValueList.Count > 0) Core.ProjectNameValueList.InvalidateCache(); } _projectNameValueList = Core.ProjectNameValueList.GetAll(); _projectNameValueListBindingSource.DataSource = _projectNameValueList; } private void _btnSaveProject_Click(object sender, EventArgs e) { /*projectListBindingSource.EndEdit(); _projectList = _projectList.Save(); projectListBindingSource.DataSource = _projectList;*/ _projectBindingSource.EndEdit(); _project = _project.Save(); _projectBindingSource.DataSource = _project; FillProjectsDropDown(); //in case name of some project has changed } private void _ucProjectsNameValue_TextChanged(object sender, EventArgs e) { _selectedProjectId = Int32.Parse(_ucProjectsNameValue.SelectedRow.Cells["Key"].Value.ToString()); FillGridWithSelectedProject(_selectedProjectId); }
It's binding to the grid and displaying the children ( I can drill down to them, loaded with lazy loading ) ... but the DEL on the parent is not working, and no functions against the children ( update/delete/insert ) are working
I'll paste how the children ( EditableChildren ) are retrieved from the database:
public partial class Project { #region Custom Made Properties private static readonly PropertyInfo<MemberList> _membersProperty = RegisterProperty<MemberList>(p => p.Members, string.Empty, null); public MemberList Members { get { return GetProperty(_membersProperty); } set { SetProperty(_membersProperty, value); } } #endregion partial void OnMapping(Csla.Data.SafeDataReader reader, ref bool cancel) { try { //loads the members (children) for the project LoadProperty(_membersProperty, MemberList.GetByParentID(Int32.Parse(reader["ProjectID"].ToString()))); } catch (Exception) { }; // this is done in case there are no children ... default CSLA behaviour is to cast error on this and I'm not fond of it ... so I just catch the error upper and ignore it }
-----I've noticed that I probably need to call the Save method of the CSLA object after I've hit "DEL" in the Grid ... to update the CSLA ... but this is not working, it's not marked as deleted ( I've debugged it ):private void _btnSaveProject_Click(object sender, EventArgs e) { /*projectListBindingSource.EndEdit(); _projectList = _projectList.Save(); projectListBindingSource.DataSource = _projectList;*/ _projectBindingSource.EndEdit(); _project.ApplyEdit(); _project = _project.Save(); _projectBindingSource.DataSource = _project; FillProjectsDropDown(); //in case name of some project has changed }----- EDIT -----
Is there any way can trigger the DEL ( which deletes from the GRID, not the datasource ) work on the CSLA object also ?
I'm now trying something like this ... which doesn't make sense I think, but if I do this I can see the CSLA object gets the status IsDeleted = true ... ( after the _project.Delete( ) ) but it does NOT enter this in the CSLA object:
public static void DeleteProject(System.Int32 projectID) { DataPortal.Delete(new ProjectCriteria {ProjectID = projectID}); } it just calls the BASE classe's Delete I guess ... ( behind the scenes ) - the delete I'm calling isn't taking any parameters ( hence ... it's the base Delete ... )
I'm trying something like this:
private void _btnSaveProject_Click(object sender, EventArgs e) { /*projectListBindingSource.EndEdit(); _projectList = _projectList.Save(); projectListBindingSource.DataSource = _projectList;*/ _projectBindingSource.EndEdit(); _project = _project.Save(); _projectBindingSource.DataSource = _project; FillProjectsDropDown(); //in case name of some project has changed }
private void _btnDelete_Click(object sender, EventArgs e) { _projectBindingSource.EndEdit(); _project = (Core.Project)_projectBindingSource.DataSource; _project.Delete(); <--- calls the BusinessBase, baseClass _projectBindingSource.DataSource = _project; FillProjectsDropDown(); //in case name of some project has changed }
Hi,
I'm really lost in this post. I'm not sure where I am even supposed to start reading.
If your grid is bound to any data source which implements IBindingList and deleting a row in the grid is not deleting that row in the data source, then the data source is failing to respond to the notifications that the grid is sending it. You should not have to do anything extra.
Hi ...
I can understand you're pretty lost reading this :-)
This is about how to implement the deletion with CSLA
I'm getting this error now:"Unable to delete row: Invalid for root objects - use Delete instead"
Can you please have a look at the bottom there ?http://forums.lhotka.net/forums/p/8779/41772.aspx#41772I've put a button on the Winform to check the deletion, and THIS is working:Core.Project.DeleteProject(_projectList[0].ProjectID);But I do NOT want to have this button ... I want the Grid to delete correctly from the EditableRoot, which is beneath the EditableRootList ( which is bound to the Grid )
Is there any EVENT on the Grid which let's me play with it?Some "OnDeleted" ... where can I manipulate the event behind the "DEL" keyboard button on the Grid?Any ideas ?
To get rid of this error I added the "MarkAsChild()" in the constructor of the EditableRoot ( which is "under" the EditableRootLIST which is databinded )
internal
Project(SafeDataReader reader){Map(reader);MarkAsChild(); //Note: I added this} and now the DataPortal_Update of the EditableRootList is entered but there are no items ... because they've already been removed:
protected override void DataPortal_Update() { //this bool cancel = false; OnUpdating(ref cancel); if (cancel) return;
RaiseListChangedEvents = false;
foreach(Project item in Items) // here the items have already been removed! { item.Save(); <--- will never enter this because of it }
RaiseListChangedEvents = true;
OnUpdated(); }rgd,EE
Well, the grid has to act on the data via the BindingManager or the IBindingList interface. If the CSLA object does not support the deletion of certain rows via these methods, then there's really nothing the grid can do about that. I suppose you could handle the grid's BeforeRowsDeleted event, cancel the event, and then delete the appropriate rows in code.
Please have a look at this ...
http://forums.lhotka.net/forums/p/9112/43310.aspx#43310
What is the UltraGrid trying to do ? You can see it works if I call the CSLA object itself ... but not through the GridWhat is the command it's sending to the bindingList ?rgd,EE
The grid doesn't call into the BindingList directly. The grid operates through the BindingManager in DotNet, and it calls the RemoveAt method and passes in the list index of the row to be deleted. It's is up to the BindingManager to take it from there.