Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1510
CSLA question: BindingSource in Infragistics UltraGrid not responding to delete command
posted

-- 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 guess

Please 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
        }

 

 

 

Parents Reply Children
No Data