Binding WebBrowser.DocumentText to a BindingSource won't update - c#

So I have a BindingSource with it's DataSource property set to a DataSet. I then have several controls that are bound to different columns of tables in the DataSet.
bsStatus.DataSource = statusDS;
dgvStatus.DataBindings.Add("DataSource", bsStatus, "Status");
lblBRId.DataBindings.Add("Text", bsStatus, "Status.BorrowerAccount");
lblCBId.DataBindings.Add("Text", bsStatus, "Status.CoBorrowerAccount");
// MORE CONTROL BINDINGS
webBrowser1.DataBindings.Add("DocumentText", bsStatus, "Status.ScriptLog");
This all works just fine on loading. My controls are populated with the correct values. The problem comes when updating the 'statusDS' DataSet. Most controls are just fine. The TextBox and DataGridView controls update just fine when the source DataSet is changed.
The problem is that the WebBrowser.DocumentText property isn't updated.

I realized I had set
WebBrowser.AllowNavigation = false
Setting it back to true solved the issue.

Related

Reload DataGrid with DataSource is too slow only when DataGrid is on the current active tab

I have TabControl and DataGrid with DataSource in one of the tabs .
When I "Reload" my DataSource (pull data from DataBase, clear DataSource and fill it again with the objects), it is too slow (a half an hour or more, for 65000 records) if current active Tab is tab where is the DataGreed. If some other Tab is active it takes 2 minutes.
I just do test with "visible=false" for DataGrid and it work fast, as normal, but it is not an option, I wanna that client see DataGreed during its reload.
It looks as the DataGrid does "something" (which slow down) after adding every single row in DataSource.
AutoSizeColumnsMode is already None
Is there any trick how I can solve this problem? any advice is appreciated.
You can try to use Background Worker to fill DataGridView.
Also what I noticed that Telerik RadGridView loads its data dynamically when moving ScrollBar.
Loading DataTable Slow When Bound to DataGridView.Datasource
To avoid rendering every row in DataGrid one by one, I set:
myDataGrid.DataSource = null;
After it fill my dataSource with the data, and after it back my original binding source.
myDataGrid.DataSource = originalBindingSource;
Problem here could be only that we will empty DataGrid during the reloading (because DataSource = null).
We can make another helping collection and set it as a DataSource, until originalDataSource is filling.

Databinding issue in C#

I have an issue with DataBindings in C#.
I have a BindingSource with it's DataSource set to a DataRowView
I then use the binding source to set all the databinding for my controls.
Here is my code:
bsDataRecord.DataSource = myDataRow; //bsDataRecord is a BindingSource and myDataRow is a DataRowView
//Add Databinding to my controls
dateNextDate.DataBindings.Add("Value", bsDataRecord, "Next_Date", false, DataSourceUpdateMode.OnPropertyChanged); //DateTimePicker
textInformation.DataBindings.Add("Text", bsDataRecord, "Information", false); //TextBox
//more controls, etc
My databindings all work fine. So as I select the control and enter a value, myDataRow is updated.
My problems occurs when I try to set a control's value in code e.g.
textInformation.Text="Test";
When I do this myDataRow isn't updated. The only way I can get myDataRow to update is to give the control that I've updated focus.
Hope that makes sense!? Anybody got any ideas?
Thanks in advance.
I'm using c#.Net 4.0.
After problematically setting a property of the data source, you need to get the controls to reread their values from the datasource. Often a simple call to
dataBindingSource.ResetBindings(false); // false for value change not schema change
But you could also per control use this:
foreach (Binding b in myControl.DataBindings) b.ReadValue();
Binding.ReadValue() causes the control's bound property to be set to the data source value
Hope this helps!
If you update a (non-two-way)binding's target "by hand", that breaks the binding and it will not work anymore. This is normal behaviour.
So make your binding two-way to achieve what you want to do.

Set DataGridView rows after all are created to stop refresh

I'm adding a great deal of rows to a data grid view, and the process is pretty slow because it appears to try to redraw after each addition.
I'm having trouble finding an example online of how to create a List (or array, whichever works) of rows and add them all at once after the list is created. I need to do this to stop it from re-drawing after each addition though.
Can anyone provide a brief example of this or point me to a good doc?
You're probably looking for the DataGridView.DataSource property. See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource(v=vs.90).aspx
For example:
//Set up the DataGridView either via code behind or the designer
DataGridView dgView = new DataGridView();
//You should turn off auto generation of columns unless you want all columns of
//your bound objects to generate columns in the grid
dgView.AutoGenerateColumns = false;
//Either in the code behind or via the designer you will need to set up the data
//binding for the columns using the DataGridViewColumn.DataPropertyName property.
DataGridViewColumn column = new DataGridViewColumn();
column.DataPropertyName = "PropertyName"; //Where you are binding Foo.PropertyName
dgView.Columns.Add(column);
//You can bind a List<Foo> as well, but if you later add new Foos to the list
//reference they won't be updated in the grid. If you use a binding list, they
//will be.
BindingList<Foo> listOfFoos = Repository.GetFoos();
dgView.DataSource = listOfFoos;
A handy event to bind to at that point is the DataGridView.DataBindingComplete which fires after the data source is bound.
Here are a couple of ideas:
1) Bind a list to the DataGridView. When you set the DataGridView.DataSource = MyList, it immediately updates the entire grid without all the line-by-line action. You can add the items to MyList and then rebind to the DataGridView. (I prefer using a BindingList which will update the DataGridView grid dynamically.)
2) If data binding is not an option, what I've done in the past is set the AutoSizeMode = NotSet for each column before the update and then set it back to whatever it was before. It is the AutoSizeMode that really slows down the drawing.

C# bound textbox will not update using tableadapter update

I am having problems getting a dataset to update changes to a database.
I start by filling a dataset using a FillBy query that I created on a table adapter.
"SELECT * FROM tblTest WHERE testID = (testID = #testId)
That will return a single record. I want to bind each column of the dataset.datatable to its own textbox on the form.
textBox1.DataBindings.Add("Text", dataset.datatable, dataset.datatable.NameColumn.ToString());
This loads the data fine. I make some changes to the data in the textbox. Then when I use the tableadapter.Update(dataset) to update the changes to the database, it does not update the record.
If I populate a datagrid with this dataset, make changes, and then run the tableadapter.update(dataset), it will update the record.
How can I use the tableadapter.update() without using the datagrid? Do I have to write a custom update for the tableadapter?
I did find out why the database was not updating. I checked the row state of the changed row and it was still in a "unmodified" state.
I changed the binding setup and created a new bindingsource with the datasource set as the dataset. and the datamember set as dataset.datatable. Then bound the control to a column in that bindingsource.
Before running the tableadapter.update(dataset) the following line is needed so that the row state changes
this.BindingSource.EndEdit();
Everything then updated properly

Deferring DataGridView update when editing the underlying DataTable

If you have a DataGridView that is bound to a DataView (someDataTable.DefaultView).
..and a number of edits are performed on rows in the underlying DataTable from code.
Is it possible to defer the updating of the DataGridView until you decide that you are finished editing rows?
As it is, the DataGridView is updated after every edit, which, if you don't require instant feedback, is inefficient and a little visually jarring if you are updating many rows in the DataTable one after the other.
In order to be able to temporarily suspend data binding, you'll have to put a BindingSource between your DataGridView and your DataView. By setting the RaiseListChangedEvents property of the BindingSource to false, changes in the underlying source are not notified to the DataGridView. You can drag & drop a Bindingsource component from the toolbox in the design view. I tried to set up the data sources via the designer but it didn't work, so I did it in code:
bindingSource1.DataSource = someDataTable.DefaultView;
dataGridView1.DataSource = bindingSource1;
To suspend data binding, just set the RaiseListChangedEvents property to false:
bindingSource1.RaiseListChangedEvents = false;
To resume data binding, just set the RaiseListChangedEvents to true and reset the bindings so the display is updated:
bindingSource1.RaiseListChangedEvents = true;
bindingSource1.ResetBindings(false);

Categories

Resources