Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Refreshing all winform Objects with new Data loaded.
Message
De
07/03/2009 12:26:48
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
01386186
Message ID:
01386424
Vues:
47
This message has been marked as the solution to the initial question of the thread.
I think the problem is that you're getting a new DataSet everytime you call the RefreshControls() method, which in effect removes your previous bindings. You should only do the following line of code once, in your load, and then not again:

Customers = CatalogAccess.GetCustomers(cCliente);

So basically, at load time, you get your data and you databind your controls and you only do that one time. You are correctly binding your controls only once, but the fact that you refresh your Data the way that you do negates that.

Now, if the reason for refreshing your Data is because you want to go back and get the latest data, in case something has changed, then you're going to have to handle it differently. Either by re-binding your controls after you re-fill your Data, or refilling your Data in a non-destructive manner, such as this:
dtTemp = CatalogAccess.GetCustomers(cCliente);
Customers.Clear();
Customers.Merge(dtTemp)
~~Bonnie



>C # 2005.
>
>Dear friends :
>
>my question is it :
>My winform have a datagridvied and some texbox.
>
>i have a method that return a DataTable with an unique record(parametrizaded store procedure in sql server).
>when the form first run the form load the a sample record, but when i type another value in the Customer id Textbox, only
>the datagridview is refreshed with the new data, the textboxs retain the the prior values.
>
>i am lookin some samples about "refreshing textbox with new data loaded" but i don't find any thing.
>i am a beginer.
>
>Your help is great appreciated:
>
>
> DataTable Customers;
> private void frmMantenimientoClientes_Load(object sender, EventArgs e)
> {
> cCliente = textBox1.Text;
> getCategories(cCliente);
> }
> private void getCategories(string cCliente)
> {
>
> if (firsload==false)
> {
> BindControls();
> firsload = true ;
> }
> else
> {
> this.RefreshControls();
> }
> }
>
>private void button1_Click(object sender, EventArgs e)
> {
> cCliente = textBox1.Text;
> getCategories(cCliente);
> }
> private void BindControls()
> {
> this.RefreshControls();
> //this.txtcustomerIDTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "CustomerID", true));
> this.txtcustomerIDTextBox.DataBindings.Add("Text", Customers.DefaultView, "CustomerID", true);
> this.txtcompanyNameTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "CompanyName", true));
> this.txtcontactNameTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "ContactName", true));
> this.txtcontactTitleTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "ContactTitle", true));
> this.txtaddressTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "Address", true));
> this.txtcityTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "City", true));
> this.txtregionTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "Region", true));
> this.txtpostalCodeTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "PostalCode", true));
> this.txtcountryTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "Country", true));
> this.txtphoneTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "Phone", true));
> this.txtfaxTextBox.DataBindings.Add(new Binding("Text", Customers.DefaultView, "Fax", true));
> }
>
> private void RefreshControls()
> {
> Customers = CatalogAccess.GetCustomers(cCliente);
> dataGridView1.DataSource = Customers.DefaultView;
> }
> }
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform