Recent Post

Tuesday, April 2, 2013

Chuột phải trong datagridview

by Unknown  |  at  3:21 AM



nay gặp phải trường hợp người dùng muốn in lại dữ liệu chọn trên datagridview lên làm cái chọn chuột phải hiện cái menustrip lên cho nó hoành tráng :))




// sự kiện load nho load cai menustrip lên


public void BC34GiaoDich_Load(object sender, EventArgs e)

{



sukieninlai();

}

// khai báo in lại


ContextMenuStrip contextMnStrip = new ContextMenuStrip();

private void sukieninlai()

{

contextMnStrip.Items.Add("In Lại");

contextMnStrip.MouseClick += new MouseEventHandler(Print_InLai);

}

//sự kiện in lại

private void Print_InLai(object serder, MouseEventArgs e)

{

//MessageBox.Show("Sự kiện in lại");

if (mact != null && mact != "")

{

ChiTietBC34 fromct = new ChiTietBC34(IDBuuCucGuiBC37, dtpNgay.Value, mact, idbuucucnhanct, sochuyenthuct, sotuict, trongluongct, tuifct, ghichuct);

fromct.Show();

}

else {

MessageBox.Show("Dữ liệu theo lô chưa lưu! Chưa thể in lại");

return;

}

}

// khai báo biến cho from in lại


string mact;

int idbuucucnhanct;

string sochuyenthuct;

int sotuict;

double trongluongct;

string tuifct;

int ghichuct;

// sự kiện click chuột phải để in lại

private void dgvBC34_MouseDown(object sender, MouseEventArgs e)

{

DataGridView.HitTestInfo hti;

if (e.Button == MouseButtons.Right)

{

hti = dgvBC34.HitTest(e.X, e.Y);

if (hti.Type == DataGridViewHitTestType.Cell)

{

if (!dgvBC34.Rows[hti.RowIndex].IsNewRow)

{

if (hti.Type == DataGridViewHitTestType.Cell && hti.RowIndex == hti.RowIndex)

{



contextMnStrip.Show(dgvBC34, new Point(e.X, e.Y));

dgvBC34.Rows[hti.RowIndex].Selected = true;

dgvBC34.CurrentCell = dgvBC34[hti.ColumnIndex, hti.RowIndex];

//Truyền biến sang from chi tiết

try

{



mact = this.dgvBC34.CurrentRow.Cells["Ma"].Value.ToString();

idbuucucnhanct = Int32.Parse(this.dgvBC34.CurrentRow.Cells["BuuCucNhan"].Value.ToString());

sochuyenthuct = this.dgvBC34.CurrentRow.Cells["SoChuyenThu"].Value.ToString();

sotuict = Int32.Parse(this.dgvBC34.CurrentRow.Cells["SoTui"].Value.ToString());

trongluongct = double.Parse(this.dgvBC34.CurrentRow.Cells["TrongLuong"].Value.ToString());

tuifct = this.dgvBC34.CurrentRow.Cells["TuiF"].Value.ToString();

ghichuct = Int32.Parse(this.dgvBC34.CurrentRow.Cells["GhiChu"].Value.ToString());



}

catch { MessageBox.Show("Anh/Chị Hãy xem lại dữ liệu chọn"); return; }



}





}

}

}

}

//// không có file đính kèm vì nó trong project của mình ko thể sent đươc ^^!

0 comments:

Proudly Powered by Blogger.