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
235
Problem in Ultragrid events
posted

Hi

I am using Ultragrid in windows form. Functionality in UI contains two features:
1. Add new Row -- Clicking this will open my detail container in add new mode instead of inline editing in grid
2. Edit Existing row in grid -- Clicking this will open detail container with existing row details and user can update those values
For add new row I am using BeforeRowInsert event in which I am cancel this row insert event and implements my own logic of intiating new row in detail container below the grid and for edit existing row I am using ClickCell event and have coded desired logic there
Now I am facing two problems:
1. After adding/editing rows, I am refreshing grid with latest data from database to avoid concurency probelms. Problem comes if while updating the grid latest data, I try to access grid row properties, grid behaves absurdly. It paints grid which means that first row of grid paints itself at the add new row place
2. Clicking on the add new row in grid, sometimes fire click cell event. I am not able to understand why it fires this event sometimes. No doubt I cann place defensive code in the click cell event, but I want to undertand why sometimes.

        private void ugrdResults_BeforeRowInsert(object sender, BeforeRowInsertEventArgs e)
        {
            //We are cancel row add event, since we want to handle it in a different manner
            e.Cancel = true;
            //Commit the unsaved changes in detail container and refresh grid with new results
            CommitUnsavedChanges(true, false);
            //Add new record in the detail container
            AddNewProgressNote();
        }


      private void ugrdResults_ClickCell(object sender, ClickCellEventArgs e)
        {
            if (ugrdResults.ActiveRow != null && !e.Cell.Row.IsAddRow && !string.IsNullOrEmpty(e.Cell.Row.Cells["pkID"].Text))
            {
  //Some processing here
            }
          
        }

     //Refresh grid method  
      private void BindGrid(Notes.ProgressNotesDataTable noteTable, bool newSearch)
        {

                //Bind the results to datagrid
                if (noteTable != null)
                {
                    //Get the default view for the table
                    dvResults = noteTable.DefaultView;
                    //apply sorting to dataview
                    dvResults.Sort = newSearch ? "noteTime asc" : sortOrder;
             //This is executed only once
                    if (o1 == null) --o1 is a private variable
                    {
                        o1 = noteTable;
                        //bind dataview to grid
                        ugrdResults.SetDataBinding(dvResults, null, true);
                        if (canEdit)
                        {
                            //add the new row as fixed row on bottom if grid has vertical scrollbar...Else add to end of rows
                            ugrdResults.DisplayLayout.Override.AllowAddNew = HasVertScrollBar(ugrdResults) ? AllowAddNew.FixedAddRowOnBottom : AllowAddNew.TemplateOnBottom;
                            ugrdResults.DisplayLayout.Override.TemplateAddRowPrompt = "(add new row)";
                            ugrdResults.DisplayLayout.Override.SpecialRowSeparatorHeight = 3;
                            ugrdResults.DisplayLayout.Override.TemplateAddRowCellAppearance.BorderAlpha = Infragistics.Win.Alpha.Transparent;
                            ugrdResults.Rows.TemplateAddRow.Height = 16;
                        }
                    }
                    else
                    {
                        ugrdResults.DataSource = dvResults;                       
                    }
                    ugrdResults.ActiveRow = null;
     // now if I writes following code here, grid creates first problem described above
    //foreach (UltraGridRow row in ugrdResults.Rows)
             // {
  
              //}
  }

        }

One more problem that I am facing is while repopulating grid, first row is shown selected alternatively though you can see (ugrdResults.ActiveRow = null) I am clearing active row of grid after refreshing data soruce

Any help wil be appriciated

Thanks
Narinder Mittal