473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

checkbox eventhandler visual c# 2008

Hello everyone,

Iam firing a event in the chechbox_checkedchanged. It works fine
Expand|Select|Wrap|Line Numbers
  1.  private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2.         {
  3.             /
  4.                 textBox1.Visible = false;
  5.                 textBox2.Visible = false;
  6.                 button2.Visible = false;
  7.  
  8.                 String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + datapath + "'";
  9.  
  10.                 using (OleDbConnection connection = new OleDbConnection(connectionString))
  11.                 {
  12.                     OleDbCommand command = new OleDbCommand("select * from userinfo WHERE ServerUrl='" + temp + "'", connection);
  13.  
  14.                     connection.Open();
  15.                     OleDbDataReader reader = command.ExecuteReader();
  16.                     if (reader.HasRows)
  17.                     {
  18.                         while (reader.Read())
  19.                         {
  20.                             String rea = reader[0].ToString();
  21.                             String reb = reader[1].ToString();
  22.                             MessageBox.Show("Username and Password are Matching Click ok to continue ..");
  23.                             groupBox2.Visible = false;
  24.                             groupBox1.Visible = false;
  25.                             groupBox3.Visible = true;
  26.                             checkBox1.Checked = false;
  27.                             newop(rea, reb, out res1, out res2);
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         MessageBox.Show("No Record please provide username and pwd");
  33.                         groupBox2.Visible = true;
  34.                         textBox1.Visible = true;
  35.                         textBox2.Visible = true;
  36.                         button2.Visible = true;
  37.                         checkBox1.Checked = false;
  38.                         groupBox1.Visible = false;
  39.                     }
  40.                     reader.Close();
  41.                     connection.Close();
  42.                 }
  43.   }
  44.  
The problem after this event when i make the checkbox visible the checkbox is in checked state. so if i make the checkbox.checkedstate= false automatically the else part in the chekedchanged event is triggering i know why it is happening?.. what are the other ways i can make the checkbox in unchecked state without firing this eventhandler or should i write the code in someother handler event of checkbox ?..

Thank you.

Dinesh.
Feb 18 '09 #1
4 4265
Hello everyone,

Iam firing a event in the chechbox_checkedchanged. It works fine
Expand|Select|Wrap|Line Numbers
  1.  private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2.         {
  3.  
  4.                 textBox1.Visible = false;
  5.                 textBox2.Visible = false;
  6.                 button2.Visible = false;
  7.  
  8.                 String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + datapath + "'";
  9.  
  10.                 using (OleDbConnection connection = new OleDbConnection(connectionString))
  11.                 {
  12.                     OleDbCommand command = new OleDbCommand("select * from userinfo WHERE ServerUrl='" + temp + "'", connection);
  13.  
  14.                     connection.Open();
  15.                     OleDbDataReader reader = command.ExecuteReader();
  16.                     if (reader.HasRows)
  17.                     {
  18.                         while (reader.Read())
  19.                         {
  20.                             String rea = reader[0].ToString();
  21.                             String reb = reader[1].ToString();
  22.                             MessageBox.Show("Username and Password are Matching Click ok to continue ..");
  23.                             groupBox2.Visible = false;
  24.                             groupBox1.Visible = false;
  25.                             groupBox3.Visible = true;
  26.                             checkBox1.Checked = false;
  27.                             newop(rea, reb, out res1, out res2);
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         MessageBox.Show("No Record please provide username and pwd");
  33.                         groupBox2.Visible = true;
  34.                         textBox1.Visible = true;
  35.                         textBox2.Visible = true;
  36.                         button2.Visible = true;
  37.                         checkBox1.Checked = false;
  38.                         groupBox1.Visible = false;
  39.                     }
  40.                     reader.Close();
  41.                     connection.Close();
  42.                 }
  43.   }
  44.  
The problem after this event when i make the checkbox visible the checkbox is in checked state. so if i make the checkbox.checkedstate= false automatically the else part in the chekedchanged event is triggering i know why it is happening?.. what are the other ways i can make the checkbox in unchecked state without firing this eventhandler or should i write the code in someother handler event of checkbox ?..

Thank you.

Dinesh.
Feb 18 '09 #2
cloud255
427 Expert 256MB
Hi

By reading your code it seems that you only want to execute this section if the check box is checked (in both the if and else you set the checked to false).

a work around might be to check if the textbox is checked before executing the code:

Expand|Select|Wrap|Line Numbers
  1. if(checkbox1.checked == true)
  2. {
  3.   //execute code
  4. }
  5. else
  6. {
  7.   return;
  8. }
if indeed you want the code to execute each time the checked state changes, i suggest you use a Boolean variable (not inside the event handler scope) to perform a similar task as described above. Neither of these methods is optimal as they both cause the event to fire more than once per user interaction.

Ultimately i would suggest that you use a command button to execute code that reads from the database, but that is a personal preference in design choice.

Good luck
Feb 18 '09 #3
Frinavale
9,735 Expert Mod 8TB
Add an if statement around your whole code checking if the checkbox is checked before executing the call to the database.

If it's not checked, don't do anything.
If it is, execute the code.
Feb 18 '09 #4
tlhintoq
3,525 Expert 2GB
[edit] Threads have been merged[/edit]

By the way, another technique for your need to would be to disconnect the event, change the checkbox, then reconnect the event.

.... -= new eventhandler ......
mycheckbox.checked = false;
... += new eventhandler ....
Feb 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tomas Vera | last post by:
Hello All, I'm having problems creating a page with dynamic checkboxes in a WebApp. In my app, I need to query a database, then (based on results) add checkboxes to my form and set their...
2
by: Thomas R | last post by:
Is is possible? In VS.NET 2003, Binding data to the repeater is easy, but when I try to add an ASP:checkbox to the .aspx page, the designer won't recognize it, hence the code view doesn't allow...
4
by: mahsa | last post by:
my problem dosent solve yet I want to have claa void in onclick of my check bov if I us function setProps ( ) msg.innerText = "llll"; in <datalist> <ItemTemplate><input type="checkbox"...
5
by: TPS | last post by:
I have a checkbox column in my datagrid. This checkbox triggers an autopostback. When I postback, I need to tell what row the user is on so I can tell what check box was checked or unchecked. ...
6
by: Alessandro Rossi | last post by:
Hi, I have to create a CheckBox, and i would like will be checked if there is a value in a property added, and not checked if there is another value. I added 2 property (string) to the checkbox;...
2
by: Nu2ASP.NET | last post by:
What I am trying to do is essentially 'flip' the bits, when the user clicks in the checkbox. For example, if the CheckBox appears checked, and the user un-checks it, I want the underlying data...
2
by: Javier | last post by:
Hi Everyone, I have a dynamic checkbox in a datagrid that uses the ITemplate interface and has the checkchanged event wired up. When the checkbox is checked, the event event handler that...
1
by: Jason Huang | last post by:
Hi, In my ASPNET 2.0 C# Web form, what's the difference between a CheckBox and a TemplateField's CheckBox? <asp:CheckBox id="CheckBoxNormal" runat="server" AutoPostBack="True" /> ...
4
by: darkminos | last post by:
Hi, I am creating dynamic checkboxes which should have an eventhandler attached to the submitButton. What I mean is while I’m changing state (check / uncheck) nothing should be happening but when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.