Wednesday, 14 December 2016

Filling Data Grid View from Database

string slctcmd = string.Format("--Your SQL Query--");
            DataTable dt = qc.DataReaderTable(slctcmd);
            DataGridView.DataSource = dt;

            DataGridView.Columns[0].Width = 200;
            DataGridView.Columns[1].Width = 100;
            DataGridView.Columns[2].Width = 100;
            DataGridView.Columns[3].Width = 100;
            DataGridView.Columns[4].Width = 100;

Friday, 2 December 2016

Upward Context Menu Strip on Button Click

private void button2_Click(object sender, EventArgs e)
        {
            Point screenpoint = button2.PointToScreen(new Point(button2.Left, button2.Bottom));
            if (screenpoint.Y + contextMenuStrip1.Size.Height < Screen.PrimaryScreen.WorkingArea.Height)
            {
                contextMenuStrip1.Show(button2, new Point(0, -contextMenuStrip1.Size.Height));
            }
            else
            {
                contextMenuStrip1.Show(button2, new Point(0, button2.Height));
            }
        }

Tuesday, 1 November 2016

Delete cnfrmation Msg

DialogResult result = MessageBox.Show("Are You Sure to Delete This?", "Attention Please...!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
            if (result == DialogResult.Yes)
            {}

SearchBox Text Changed Event

private void txt_Search_TextChanged(object sender, EventArgs e)
        {
            dgv_search.Rows.Clear();
            string aq = "SELECT [Name],[Description],[Date] FROM [City] where Name like '%" + txt_Search.Text + "%'";
            DataTable dt = qc.DataReaderTable(aq);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dgv_search.Rows.Add();
                dgv_search.Rows[i].Cells[0].Value = Convert.ToString(dt.Rows[i]["Name"]);
                dgv_search.Rows[i].Cells[1].Value = Convert.ToString(dt.Rows[i]["Description"]);
                dgv_search.Rows[i].Cells[2].Value = Convert.ToDateTime(dt.Rows[i]["Date"]);
            }
        }

btn Edit

txt_Name.Text = Convert.ToString(dgv_search.SelectedRows[0].Cells[0].Value);
                txtDesc.Text = Convert.ToString(dgv_search.SelectedRows[0].Cells[1].Value);
                dtp_Date.Text = Convert.ToString(Convert.ToDateTime(dgv_search.SelectedRows[0].Cells[2].Value));

Filling Grid from text fields

int _dgrow = dgvSOUT.Rows.Count;

                    dgvSOUT.Rows.Add();
                    dgvSOUT.Rows[_dgrow].Cells[0].Value = dgvSOUT.Rows.Count;
                    dgvSOUT.Rows[_dgrow].Cells[1].Value = cmblot.Text;
                    dgvSOUT.Rows[_dgrow].Cells[2].Value = txtSName.Text;
                    dgvSOUT.Rows[_dgrow].Cells[3].Value = txtbrand.Text;

Filling textbox

private void fillParty()
        {
string selectPartyCmd = string.Format("SELECT DISTINCT [Cust_Name] FROM [CUSTOMER] where [Loc_Id] = '" + Program.locId + "'");
                txtPName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                txtPName.AutoCompleteSource = AutoCompleteSource.CustomSource;
                AutoCompleteStringCollection coll = new AutoCompleteStringCollection();
                coll = qc.txtAutoCollection(selectPartyCmd);
                txtPName.AutoCompleteCustomSource = coll;
}