make databound checkbox checked in C#.net2005 winform application
normal checkbox can use checkbox1.checked = true;
databound checkbox needs to change the checkstate: checkbox1.checkstate = checkstate.checked;
Achievement provides the only real pleasure in life
normal checkbox can use checkbox1.checked = true;
databound checkbox needs to change the checkstate: checkbox1.checkstate = checkstate.checked;
Posted by
SF
at
11:12 pm
0
comments
normal checkbox can use checkbox1.checked = true;
databound checkbox needs to change the checkstate: checkbox1.checkstate = checkstate.checked;
Posted by
SF
at
11:12 pm
0
comments
created the form object in application settings
Code to open the form:
private void button1_Click(object sender, EventArgs e) {
if ( Properties.Settings.Default.frmReg == null )
{
Properties.Settings.Default.frmReg = new frmRegistration();
Properties.Settings.Default.frmReg.Show( this );
}
else if ( Properties.Settings.Default.frmReg != null && Properties.Settings.Default.frmReg.WindowState ==
FormWindowState.Minimized)
{
Properties.Settings.Default.frmReg.WindowState = FormWindowState.Normal ;
}
else
{
Properties.Settings.Default.frmReg.Focus();
}
}
Code to close the opened form:
Properties.Settings.Default.frmReg = null;
Posted by
SF
at
11:10 pm
0
comments
what's happening with blogger.com? the whole weekend and this monday morning, sometimes can't create a new post, sometimes changes to the template are not reflected, come on!!!!!
Posted by
SF
at
9:06 am
0
comments
created the form object in application settings
Code to open the form:
private void button1_Click(object sender, EventArgs e) {
if ( Properties.Settings.Default.frmReg == null )
{
Properties.Settings.Default.frmReg = new frmRegistration();
Properties.Settings.Default.frmReg.Show( this );
}
else if ( Properties.Settings.Default.frmReg != null && Properties.Settings.Default.frmReg.WindowState == FormWindowState.Minimized)
{
Properties.Settings.Default.frmReg.WindowState = FormWindowState.Normal ;
}
else
{
Properties.Settings.Default.frmReg.Focus();
}
}
Code to close the opened form:
Properties.Settings.Default.frmReg = null;
Posted by
SF
at
1:02 am
0
comments
using ( OleDbConnection connection = new OleDbConnection( Properties.Settings.Default.HPMConnectionString ) )
{
connection.Open();
OleDbCommand changeActiveToNoCommand = new OleDbCommand( "UPDATE staff SET active = no WHERE staff_id = @staff_id" , connection );
changeActiveToNoCommand.Parameters.AddWithValue( "@staff_id" , Convert.ToInt64( staff_id ) );
changeActiveToNoCommand.ExecuteNonQuery();
}
Posted by
SF
at
10:53 pm
0
comments
string staff_no = staffDataGridView.CurrentRow.Cells[0].Value.ToString();
string staff_id="";
using (OleDbConnection connection = new OleDbConnection(Properties.Settings.Default.HPMConnectionString))
{
//OleDbCommand findStaffIDCommand = new OleDbCommand("SELECT staff_id FROM staff WHERE staff_no = '" + staff_no + "'", connection);
OleDbCommand findStaffIDCommand = new OleDbCommand( "SELECT staff_id FROM staff WHERE staff_no = @staff_no",connection );
findStaffIDCommand.Parameters.AddWithValue( "@staff_no" , staff_no );
connection.Open();
OleDbDataReader reader = findStaffIDCommand.ExecuteReader();
while (reader.Read())
{
staff_id = (reader[0].ToString());
}
reader.Close();
}
MessageBox.Show( staff_id.ToString() );
Posted by
SF
at
10:40 pm
2
comments
MessageBox.Show(clientsDataGridView.CurrentRow.Cells[0].Value + "");
Posted by
SF
at
11:45 am
0
comments
in winform applications, there is a component called "tooltip", which can be referenced by other visual components
in asp.net applications, there is a property called "tooltip" for most of the visual components, which can be used to enter single line tooltipss.
There is a third party tooltip utility called "cooltip", which is much more powerful:
http://www.acooltip.com/index.html#
Posted by
SF
at
11:45 am
0
comments
change the value of property "DropDownStyle" to "DropDownList)
Posted by
SF
at
8:33 pm
0
comments
if you create a class within a subfolder of a winform project, you can't reference it within he code of a class in the root folder of project.
Solution:
to create the class in the same folder/rootlevel as the class that needs to have referencing code, and then move the class into anyother folder
Posted by
SF
at
3:50 pm
0
comments
to access the values predefined in application settings, do this:
label1.Text = Properties.Settings.Default.aaa;
aaa is the name of the variable;
to persist the change, do this:
Properties.Settings.Default.aaa = "bbb";
Properties.Settings.Default.Save();
Posted by
SF
at
11:39 am
1 comments
it's been a while.....
busy doing my masters and working at the same time. have to submit a report next monday, another one is coming soon.
feel lost.....
Posted by
SF
at
8:01 pm
0
comments
This built-in function can be used to force user to input numbers:
if (!char.IsNumber(e.KeyPress))
messagebox.show("plz enter numbers only")
also, "decimal.tryparse" can be used to check if the input is a number after input
Posted by
SF
at
1:10 am
0
comments
Posted by
SF
at
1:17 pm
0
comments
this chunk of code calculates Fibonacci Sequence number base on user input using C#.NET:
private void btnGetNumber_Click(object sender, EventArgs e)
{
try
{
if (txtInput.Text == "" txtInput.Text == null) //to avoid empty input
{
MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: Empty Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtInput.Clear();
txtInput.Focus();
}
else
{
int theNum = Convert.ToInt16(txtInput.Text);
if (theNum == 0) //to avoid zero input
{ MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: Zero Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtInput.Clear();
txtInput.Focus();
}
else if (theNum <> 46) //to avoid overflow result, if the variables are defined for bigger values, this condition should be commented out and use OverflowException
{
MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: Result Overflew", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtInput.Clear();
txtInput.Focus();
}
else //all conditions met, calculate the result
{
int numA = 0; int numB = 1; int numC;
for (int i = 1; i <= theNum; i++)
{
numC = numA;
numA = numB;
numB = numC + numB;
}
//print result to screen
lblAnswer.Text = numA.ToString();
} } }
//uncomment the code below for catching overflow exception when the variables are
//defined as uint64 or ulong, that is, too big to guess the limit
//catch (OverflowException)
//{
// MessageBox.Show("Please try again with another smaller positive Integer", "Error: Result OverFlow", MessageBoxButtons.OK, MessageBoxIcon.Error);
// txtInput.Clear();
// txtInput.Focus();
//}
//throw error for string or decimal inputs
catch (FormatException)
{
MessageBox.Show("Please input a positive Integer between 0 and 62", "Error: String or decimal Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtInput.Clear();
txtInput.Focus();
}
//throw error for unknown errors
catch (Exception ee) { MessageBox.Show("Error: Unknown", ee.Message); Application.Exit(); } }
Posted by
SF
at
12:50 pm
0
comments
uint holds only positive numbers, this event checks if the input is a validate positive integer, otherwise throw error using C#.NET
private void button1_Click(object sender, EventArgs e)
{
uint value = 0;
if (!uint.TryParse(textBox1.Text, out value) value == 0)
{MessageBox.Show("Wrong format");
return;}
textBox2.Text = value.ToString();
}
Posted by
SF
at
12:26 pm
0
comments
![]()
just done a sample, hope its helpful for newbies like me
Click here to download phploginsample.rar. Don't forget to create a db called news_users, with 3 columns "username" (varchar/char, PK), "passwd" (varchar/char), and "access_level"(smallint, 0 or 1).
Posted by
SF
at
9:45 pm
0
comments
![]()
silly word wrap, some environment doesnt support automatically word wrap when copy and paste code. so the solution is:
put "//" in front of every line of comment to prevent the error caused by a multiline comment led by only have "//" in front of first line.
copy-pasters be aware!
Posted by
SF
at
9:29 pm
0
comments