Saturday, 10 November 2012

How to Set the Back color for MDI Parent Form in C#.net Windows Applications


we know How to set the back color for the windows forms but MDI parent Not like that,because this is parent form to multiple child forms so that it follows different Specifications and Designs so we con't set the BackColor by statically,we do only  this by programatically show below how is.
 

above figure Normal MDI Parent without Color
code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Blogcode
{
    public partial class Mdicolor : Form
    {
        public Mdicolor()
        {
            InitializeComponent();
        }

        private void Mdicolor_Load(object sender, EventArgs e)
        {
            MdiClient chld;

            foreach (Control ctrl in this.Controls)
            {
                try
                {
                    chld = (MdiClient)ctrl;

                    chld.BackColor = this.BackColor;
                }

                catch (InvalidCastException exe)

                {

                }
            }
        }
    }
}



above figure Normal MDI Parent Form with Color

I hope this code will help you
Read more ►

How to delete the selected Rows from dataGridView in C#.net

Here we discuss about How to delete the selected Rows from dataGridView,Most of the times our operations are doing from dataGridview
only,we performed Save,Delete,Search etc.Like that here we discuss about Delete Selected rows from dataGridView for that we gave the code for that and screenshots given below.



Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Blogcode
{
    public partial class dgvSlctRwsDel : Form
    {
        public dgvSlctRwsDel()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
              {
                 if (!row.IsNewRow)
                    {
                    dataGridView1.Rows.Remove(row);
                    }
                    MessageBox.Show("Selected rows Deleted");
             }
        }
    }
}

This code only for dataGridView selected rows only not for DataTable (or) DataBase,If you want to Delete in DataTable and also Database
we need to "update"these dataGridView after perform Delete operation for that we use "commandBuilder"object to update the Database.


I hope this code will help you.
Read more ►

Friday, 9 November 2012

How to Validate the TextBox with Indian Phonenumber Format


 Here we have discuss about the TextBox Validation,for that TextBox takes The Only indian Format Phnumber,for that here is the code for it,and also we have to using one more Namespace is using System.Text.RegularExpressions;
Code for Indian Formate Phone Number:
this code write in the txtPhnumbr_Validating Event

            Regex phNum = new Regex("^\\+[9][1][-][\\d]{10}$");

            Match getmatch = phNum.Match(textBox1.Text);

            if (getmatch.Success)
            {
                errorProvider1.SetError(this.textBox1, "");
            }
            else
            {
                errorProvider1.SetError(this.textBox1, "Phnum Should 10 Digits and Format +91-XXXXXXXXXX");
            }

Here  is the Screen shots for the TextBox Validation with the indian Format Phnumber
figure one shows the error:



Figure two shows the currect Validation:

 Here we use the errorProvider to show the error.

I hope this  code snippet will help you
Read more ►

How to Validate the Text Box ,It takes only Currency Value

 Here we discuss the How to validate the TextBox with Currency value.For  currency TextBox some Specifications are there,That are
1)TextBox takes only numeric values,
2)TextBox text align into Right side of the TextBox after Leaving the TextBox With ".00"
This is the common specification to every currency TextBox



Code for Currency Text Box:

we have to write this code in the Textbox KeyPressEvent

     private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(char.IsLetter(e.KeyChar))
            {
                e.Handled=true;
            }
        }

And one Specification is ".00" in right side of the text after leaving for these we write the code in the TextBox leaving Event,
See the below figure:


 private void textBox1_Leave(object sender, EventArgs e)
        {
            double x;
           
            double.TryParse(textBox1.Text, out x);

            textBox1.Text = x.ToString(".00");                //adding the .00 every Currency data
           
            textBox1.RightToLeft = RightToLeft.Yes;   //set the data at right side of the textbox
        }

I hope this code will Help you
Read more ►