or
Private Sub DOCFirstDtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DOCFirstDtn.Click If DocumentsGV.Rows.Count > 0 Then DocumentsGV.Rows(0).IsSelected = True DocPreviousBtn.Enabled = False DocNextBtn.Enabled = True End If End Sub Private Sub DocLastBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DocLastBtn.Click If DocumentsGV.Rows.Count > 0 Then DocumentsGV.Rows(DocumentsGV.Rows.Count - 1).IsSelected = True DocNextBtn.Enabled = False DocPreviousBtn.Enabled = True End If End Sub Private Sub DocPreviousBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DocPreviousBtn.Click If DocumentsGV.Rows.Count > 0 Then Dim SelectedRowIndex As Integer = DocumentsGV.SelectedRows(0).Index If SelectedRowIndex = 1 Then DocPreviousBtn.Enabled = False Else DocPreviousBtn.Enabled = True End If DocNextBtn.Enabled = True DocumentsGV.Rows(SelectedRowIndex - 1).IsSelected = True End If End Sub Private Sub DocNextBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DocNextBtn.Click If DocumentsGV.Rows.Count > 0 Then Dim SelectedRowIndex As Integer = DocumentsGV.SelectedRows(0).Index Dim vvv As Integer = DocumentsGV.SelectedRows.Count If SelectedRowIndex = (DocumentsGV.Rows.Count - 2) Then DocNextBtn.Enabled = False Else DocNextBtn.Enabled = True End If DocPreviousBtn.Enabled = True DocumentsGV.Rows(SelectedRowIndex + 1).IsSelected = True End If End Sub
I have a List called “myResults”. When the list contains at least one item, I’m trying to populate a GridView w/ info for the list; the GridView is called “gvMyResults”. However, sometimes, during this update of the DataSource, I get an exception saying, “Bounds cannot be changed while locked”, and a red X is displayed across my GridView. I added this Dispatcher wrapper around my update, but I’m still seeing the same error. It’s difficult to troubleshoot, because it does not happen every time. Does anyone know how to stop this “bounds cannot be changed while locked” error?
I have tried to fix this two ways, but both still give the error.
First attempt:
Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate(){ this.gvMyResults.DataSource = myResults;});Second attempt:
_Context.Send(x =>{ this.gvMyResults.DataSource = myResults;}, null);
private void Form1_Load(object sender, EventArgs e) GridViewTextBoxColumn col1 = new GridViewTextBoxColumn();
col1.HeaderText = "Stretch1"; col1.MinWidth = 100; col1.Width = 200; GridViewTextBoxColumn col2 = new GridViewTextBoxColumn(); col2.HeaderText = "Stretch2"; col2.MinWidth = 100; col2.Width = 200; GridViewTextBoxColumn col3 = new GridViewTextBoxColumn(); col3.HeaderText = "Static"; col3.MaxWidth = 200; col3.MinWidth = 200; col3.Width = 200; Telerik.WinControls.UI.RadGridView grid = new RadGridView();
grid.Location = new Point(0, 0);
grid.Size = new System.Drawing.Size(600, 100); grid.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; grid.MasterTemplate.Columns.AddRange(new GridViewDataColumn[] { col1, col2, col3}); Controls.Add(grid);