Connecting Tech Pros Worldwide Forums | Help | Site Map

Refresh textbox/combobox/datagridview when multiple tabs selected

Newbie
 
Join Date: Oct 2008
Posts: 5
#1: Oct 6 '08
Hi,

I'm developing a program in c# 2005 and would like to know if it is possible to refresh a tab page's controls(e.g textboxes, combobox, datagridview) when a different tab is selected so when i go back to the previous tab, i don't want to see any data but rather the controls blank or refreshed. I've tried to work with selectedindexchanged but to no avail could i resolve the problem. My code looks something like this(please excuse if it looks poor as i was just messing around with the code):-
Expand|Select|Wrap|Line Numbers
  1. private void tbInsertUpdateDeleteView_SelectedIndexChanged(object sender, EventArgs e)
  2.         {
  3.             if (tbInsertUpdateDeleteView.SelectedTab == tbTeams1)
  4.             {                
  5.                 cmbTeamNo.SelectedIndex = -1;
  6.                 txtMember1_1.DataBindings.Clear();
  7.                 txtMember2_2.DataBindings.Clear();
  8.                 txtMember3_3.DataBindings.Clear();
  9.                 txtMember1_1.Clear();
  10.                 txtMember2_2.Clear();
  11.                 txtMember3_3.Clear();
  12.                 dgvTeams.DataSource = null;
  13.  
  14.             }
  15.  
  16.             if (tbInsertUpdateDeleteView.SelectedTab == tbTeams2)
  17.             {
  18.                 txtTeamNo.Clear();
  19.                 txtMember1.Clear();
  20.                 txtMember2.Clear();
  21.                 txtMember3.Clear();
  22.                 dgvTeams.DataSource = null;
  23.             }
  24.  
  25.             if (tbInsertUpdateDeleteView.SelectedTab == tbTeams3)
  26.             {
  27.                 txtTeamNo.Clear();
  28.                 txtMember1.Clear();
  29.                 txtMember2.Clear();
  30.                 txtMember3.Clear();
  31.                 cmbTeamNo.SelectedIndex = -1;
  32.                 txtMember1_1.DataBindings.Clear();
  33.                 txtMember2_2.DataBindings.Clear();
  34.                 txtMember3_3.DataBindings.Clear();
  35.                 txtMember1_1.Clear();
  36.                 txtMember2_2.Clear();
  37.                 txtMember3_3.Clear();
  38.             }
  39.         }
  40.  
Any help would be appreciated. Thanks

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Oct 6 '08

re: Refresh textbox/combobox/datagridview when multiple tabs selected


Just set everything to blank when that tabpage becomes active?
That looks like what you are trying to do, so what is the actual problem?
Newbie
 
Join Date: Oct 2008
Posts: 5
#3: Oct 6 '08

re: Refresh textbox/combobox/datagridview when multiple tabs selected


Quote:

Originally Posted by Plater

Just set everything to blank when that tabpage becomes active?
That looks like what you are trying to do, so what is the actual problem?

The problem is, it doesn't work. If i select another tabpage and go back to my previous tabpage, nothing becomes blank. I can still see the data I either selected or viewed in a datagrid
Newbie
 
Join Date: Oct 2008
Posts: 5
#4: Oct 6 '08

re: Refresh textbox/combobox/datagridview when multiple tabs selected


Ok let me try to make another scenario for better understanding hopefully. Say i got 2 tabs (Create Team, View Team). Now i create couple teams, and i wish to view the teams in a datagrid which i do and i can see the teams i created. Now of course i can create a button to clear the datagrid, but instead i want to go back to the create team tabpage to create another team and when i go back to view team tabpage, i want to see the datagridview automatically blank or refreshed without me having to use a button to clear the datagrid.......
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#5: Oct 6 '08

re: Refresh textbox/combobox/datagridview when multiple tabs selected


Have you set breakpoints to see if that code ever gets executed?
I see your function that clears the databindings....but where does it get populated?
Newbie
 
Join Date: Oct 2008
Posts: 5
#6: Oct 7 '08

re: Refresh textbox/combobox/datagridview when multiple tabs selected


Sorry for the delay in reply. Yes I did try breakpoints but still no success. I doubt this will work so I have decided to scrap the idea and work try something. Thanks for the quick responses. I do appreciate it.
Newbie
 
Join Date: Oct 2008
Posts: 5
#7: Oct 7 '08

re: Refresh textbox/combobox/datagridview when multiple tabs selected


Sorry i meant try something else
Reply