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 grid2. Edit Existing row in grid -- Clicking this will open detail container with existing row details and user can update those valuesFor 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 thereNow 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
ThanksNarinder Mittal
Hi Mike
We are exploring the functionality of RowEditTemplate
In meantime, can u please suggest another feasible option
Thanks
Narinder
Hi Narinder,
Are you aware of the grid's RowEditTemplate functionality? A RowEditTemplate allows you to create a form or a control in which the user can edit the fields of a row. It sounds like you are trying to implement this yourself, but you are going through a lot of trouble and running into problems doing something that the grid already has built-in. The RowEditTemplate functionality has presumably already solved the problems you are having, so you might want to try using that, instead.