How to Login a application by pressing Enter key in the Keyboard after entering username and password using windows forms in C#.net || Login application by pressing enter key from keyboard with out using mouse in windows forms C#.net


To login any application by pressing Enter key in the keyboard after entering username and password  for that first I am taking two labels, two textboxes and one login button for design.
The design is looks like below:



Then write the following code in Code behind side:
First write the code for login button as per your requirement
  private void btnLogin_Click(object sender, EventArgs e)
        {

         
            //Login Code


         }
First check enter key ASCII value with pressing key from keyboard.
Enter key ASCII value is 13.
To know all keyboard keys ASCII values Click Here.

Then write the following code in  password textbox key press event :
private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.Equals(Convert.ToChar(13)))
            {
                btnLogin_Click(sender, e);
            }
        }


Then run your application and give username and password then click enter key then automatically it will login without  using mouse. 



Silverlight Important Interview Questions with Answers in dotnet for 1 Year Experience


What is Silverlight?

Silverlight is a cross-browser, cross-platform plug-in for delivering the next generation of Microsoft .NET–based media experiences and rich interactive applications for the Web.

Is Silverlight the official name for "WPF/E"?

Yes. Silverlight was formerly code-named "WPF/E."

What is Silverlight Tool Kit?

Silverlight Tool kit is nothing but is a collection of Silverlight Tools, Components etc. It includes source code describing the all you need to develop an application. 

Editors Supported in Silverlight ? 

1.Visual Studio
2.Visual Web Developer
3.Expression Blend 

What are the Features of Silverlight ?
Features Of SilverLight Click here

Does silverlight web application work with all browsers ?


Yes, A web application developed by silverlight technology can work with any browser

What is XAML in Silverlight ?

 Extensible Application Markup Language (XAML, pronounced zammel) is a declarative XML-based language created by Microsoft which is used to initialize structured values and objects.

Is Silverlight free of Charge?

Yes, Microsoft has made the Silverlight browser plug-in freely available for all supported platforms and browsers.

Difference between WPF and Silverlight  ?

 WPF(Windows Presentation Foundation) use for the Desktop Application and SilverLight is use for
Web Applications (Rich Internet Applcaions).
In terms of features and functionality, Silver light is a sub set of Windows Presentation Foundation.
Silver light is for developing rich internet applications. While WPF is used for developing enhanced graphics applications for desktop platform.
WPF uses XAML for hosting the user interface for web applications. 

What kind of Audio and Video formats are supported in  Silverlight ?

Silverlight Supports
WMA,
WMV7-9,
VC-1, and
MP3 Audio .

Can I consume WCF and ASP.NET Web Services in Silverlight? 
Yes
What are the main components of Silverlight application?

Following are the main component of Silverlight application.
a)Input – It handles input from devices like keyboard, mouse etc.
b)UI core –It manages rendering of bitmap images, vector graphics, text and animations.
c)Media – It handles the playback of MP3, WMA Standard, WMV7, WMV8 streams.
d)XAML – This manages UI layout to be created by XAML markup language


Layout Manager controls in Silverlight ?

                  1.Canvas
                  2.StackPanel
                  3.Grid
                  4.Border
                  5.You can always create your own



 How to set Silverlight contents width as 100%?

Generally you can't set the UserControl width in % like 100% so that the Silverlight contents can spread in the full screen. 
To get the 100% width of the screen you can set width="auto" and height="auto".




How to Insert, Edit, Update and Delete Data with DataGridView in Windows Form C#.net ||Inserting , Updating and Deleting with DataGridView in Windows forms C#.net


In this article I am showing to Inserting , Editing , Updating and Deleting options with DataGridview.
For that I am Designing form with two textboxes with Name and Location ,DataGridview to display data and four buttons to Save , Edit , Update and Delete.
To do this just follow below steps:
·         In form load I am binding the data from database.
·         In save button click event saving data to database which are inserted into the name and location textboxes.
·         In Delete button click event  Deleting the selected row data in DataGridview from database.
·         In Edit button Click event filling the selected data from Gridview into Name and location textboxes.
·         In Update Button click event updating data which are edited the name and location textboxes.
Write the following code in Form.cs :
Form.cs 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;
using System.Configuration;
using System.Data.SqlClient;

namespace savedata
{
    public partial class Form1 : Form
    {

        SqlConnection con = newSqlConnection(ConfigurationManager.ConnectionStrings["Sqlcon"].ConnectionString);
        public Form1()
        {
            InitializeComponent();
            Bind();

        }

        private void Clear()
        {
            txtName.Text = string.Empty;
            txtLocation.Text = string.Empty;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Insert Into Test_Data(Name,Location) Values (@Name,@Location)", con);
            cmd.Parameters.AddWithValue("Name", txtName.Text);
            cmd.Parameters.AddWithValue("Location", txtLocation.Text);
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("Inserted sucessfully");
            Bind();
            Clear();
        }

        private void Bind()
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("select * from Test_Data", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            con.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            SqlCommand delcmd = new SqlCommand();
            if (dataGridView1.Rows.Count > 1 && dataGridView1.SelectedRows[0].Index != dataGridView1.Rows.Count - 1)
            {
                delcmd.CommandText = "DELETE FROM Test_Data WHERE ID=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "";
                con.Open();
                delcmd.Connection = con;
                delcmd.ExecuteNonQuery();
                con.Close();
                dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
                MessageBox.Show("Row Deleted");
            }
            Bind();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("Update Test_Data set Name=@Name,Location=@Location Where(Name=@Name)", con);
            cmd.Parameters.AddWithValue("@Name", txtName.Text);
            cmd.Parameters.AddWithValue("@Location", txtLocation.Text);
            cmd.ExecuteNonQuery();
            MessageBox.Show("updated......");
            con.Close();
            Bind();
            Clear();
        }

        private void btnEdit_Click_1(object sender, EventArgs e)
        {
            int i;
            i = dataGridView1.SelectedCells[0].RowIndex;
            txtName.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
            txtLocation.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();
        }
    }
}


Then run the application you will get output like below:



How to Bind Data to ComboBox from Database in Windows Forms application C#.net || How to Set Default Select Item in ComboBox 0th index.


To bind data to ComboBox in Windows forms follow the steps below:

First Design form with One ComboBox from toolbox in visualstudio.
Then write one ComboBoxBind() method in code behind side and call that method in form load.


Form.cs 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;
using System.Data.SqlClient;

namespace combox_binding
{
    public partial class Form1 : Form
    {
        SqlConnection con = new SqlConnection("Data Source=naresh;Initial Catalog=employee;User ID=sa;Password=123");
        public Form1()
        {
            InitializeComponent();
            ComboBoxBind ();
        }

        private void ComboBoxBind ()
        {
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("Select empID,empname from emp", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            DataRow dr;
            dr = dt.NewRow();
            dr.ItemArray = new object[] { 0, "---Select an item---" };
            dt.Rows.InsertAt(dr, 0);
            comboBox1.DisplayMember = "empname";
            comboBox1.ValueMember = "empID";
            comboBox1.DataSource = dt;
            con.Close();
        }

    }
}

Then run the application and see the data will be bind to ComboBox.

OutPut :