Hello,
Is there way to obtain a UltraGridRow from a DataRow? Please advise.
Adrian
BTW... using GetRowWithListIndex is not very efficient. This method loops through the grid's Rows collection.
If you just want to populate an unbound column, it would be more efficient (not to mention easier) to just use the InitializeRow event of the grid.
Hi,
Oh, in that case, the problem is probably that the grid hasn't yet responded to the notification from the data source. So if you add a row to your data source and then immediately, on the next line of code, try to get the grid row, it may not work, because the grid responds to DataSource notification asynchronously. Since your code is working synchronously, the row doesn't exist in the grid, yet.
This is easy to fix. The grid will update itself the next time it paints. So before you call GetRowWithListIndex, you can force the grid to paint by calling grid.Update. This should work, unless you are using BeginUpdate or the grid is not visible.
Thank you Mike. The problem is not with the AddNew row. I add some rows to a typed dataset by code using companyDepositBO.CompanyDepositDetail.AddCompanyDepositDetailRow( newRow ), so all they have System.Data.DataRowState.Added state. The dataset is bound to the assignedReceiptsGrid grid, then when I loop through the dataset (begining with the last row in the collection) to GetRowWithListIndex using one of those added rows (every row in the "for") I get a null UltraGridRow. I'm sure the row exists in the dataset and that it is shown in the grid. Is this the normal behavior? I'm wondering if there are another way to get the underlying UltraGridRow (in my first post I said datarow, my mistake)? I need to have acces to an unbound column (gRow.Cells[ "UnAssign" ]) in the grid for every row in the dataset.
The AddNew row is always the last one in the collection. You could check to see if the row is an AddNew row and if so use:
assignedReceiptsGrid.DisplayLayout.Rows.Rows[assignedReceiptsGrid.DisplayLayout.Rows.Count - 1]
Why GetRowWithListIndex returns null when the datarow state is Added? Is there any other way to get the underlying datarow?
private void btnUnassign_Click( object sender, EventArgs e ) { for( int i = companyDepositBO.CompanyDepositDetail.Rows.Count - 1; i >= 0; i-- ) { WebRef.CompanyDepositBO.CompanyDepositDetailRow row = companyDepositBO.CompanyDepositDetail[ i ]; if( row.RowState == System.Data.DataRowState.Deleted ) continue;
// This returns null if the DataRow state is Added. ultraWinGrid.UltraGridRow gRow = assignedReceiptsGrid.DisplayLayout.Rows.GetRowWithListIndex( companyDepositBO.CompanyDepositDetail.Rows.IndexOf( row ), true );
// "UnAssign" is a check type unbound column. This will fail when gRow is null. if( (bool) gRow.Cells[ "UnAssign" ].Value ) { // Do something... } } }