I programmatically changed the value of a cell but it does not appear to be persisting. I tried UpdateData() prior to saving the bound sourcelist, but the row is not flagged as changed. How can I force this?
Also, in addition I would like to programmatically select each row in a foreach loop and not sure how to do this:
For example:
foreach (UltraGridRow row in grdStatus){ // doing long-running stuff per row and would like to show a highlighted row selection on the grid}
Finally, I would like to add an unbound progress bar in a cell that will show percent completed in the above iteration. Is this doable?
1) Another option is to set your grid's updatemode property to OnCellChargeOrLostFocus. This will force updates as soon as the cell has been changed. The default mode is to wait until the user exists the row.
2) You can select one or more rows by setting the row object's selected property to true in your loop. The only thing I see in your code is that your loop needs to be for each row in grdStatus.Rows.
3) You can create an unbound column and add a progress bar control as the editor. All you should have to do when processing that row is grab a reference to the row's editor control.
I can't quite figure out how to update the values in the progressbar control. Can you provide a code snippet on how to do this?
The Value of the progressbar inside the cell comes from the value of the cell. So the column's DataType probably need to be an integer in this case. You may also need to set the MinValue and MaxValue properties on the grid column to provide the range of the progress bar.
I tried doing this, but my progress bar only shows 0% and will not update.
Code fragments are as follows (with the last event handler method the attempt to update the value):
private void InitializeComponents{ [...] ultraGridColumn9.EditorControl = this.ultraProgressBar1; ultraGridColumn9.Header.VisiblePosition = 8; ultraGridColumn9.MaxValue = 100; ultraGridColumn9.MinValue = 0; [...]}
delegate void ProcessNewAddDelegate();
// this is called when a new backup request is added to the gridprivate void ProcessNewAdd(){ lock (this) { foreach (UltraGridRow row in grdStatus.Rows) { _activeRow = row; if (row.Cells["Status"].Text.ToUpper() == "PENDING") { row.Selected = true; string dbname = _tablename[row.Cells["DBName"].Text]; string backupsetname = row.Cells["BackupName"].Text; row.Cells["Status"].Value = "Active";
Backup(dbname, backupsetname);
row.Cells["Status"].Value = "Completed"; row.Cells["End"].Value = DateTime.Now; grdStatus.UpdateData(); _capturesList[0].Save(); } } }}
private void Backup(string dbname, string backupsetname){ BackupDeviceItem bdi = default(BackupDeviceItem); Database db = default(Database);
db = _server.Databases[dbname]; bdi = new BackupDeviceItem(@"\CARDbackup\" + backupsetname + ".bak", DeviceType.File);
Backup bk = new Backup(); bk.Action = BackupActionType.Database; bk.BackupSetDescription = "Full backup of " + dbname; bk.BackupSetName = backupsetname; bk.Database = dbname; bk.Devices.Add(bdi); bk.Incremental = false; bk.LogTruncation = BackupTruncateLogType.Truncate; bk.Initialize = true; // setting up event handler for backup progress bk.PercentCompleteNotification = 10; bk.PercentComplete += new PercentCompleteEventHandler(rs_PercentComplete); bk.Complete += new ServerMessageEventHandler(rs_Complete);
bk.SqlBackup(_server);
bk.Devices.Remove(bdi); bk.PercentComplete -= new PercentCompleteEventHandler(rs_PercentComplete);}
private void rs_PercentComplete(object sender, PercentCompleteEventArgs e){ // SMO sending backup completion progress event here... not working! _activeRow.Cells["Progress"].EditorResolved.Value = e.Percent; }
I don't see any code here that sets the value of the progress bar cell. You seem to be setting the value on the EditorResolved of the cell instead of the Value property on the cell itself. Why are you doing that?
I couldn't find a single code example on this and was confused. I saw something somewhere that lead me to believe that this property was a reference to the control within the cell. Setting the actual cell did the trick.
I.e.: _activeRow.Cells["Progress"] = e.Percent;