English 中文(简体)
我如何在我以方案方式制作的数据网格上开展一个单元DoubleClick活动? C#
原标题:How can I do a CellDoubleClick event on my datagridview that I created programmatically? C#

我在小组内设立了一个由方案组成的小组,是我的数据网格,也是方案性的。 它列出了供应商名单,我希望就这一数据进行<编码>CellDoubleClick的活动,以便获得其身份证,小组和数据网格将隐藏/储存。 我如何能够这样做?

    DataGridView dgvSupp;

    private void cbSuppID_Click(object sender, EventArgs e)
    {
       pGeneral.Controls.RemoveByKey("pCatHierarchy");
       Panel pSupp = new Panel();
       pSupp.Size = new System.Drawing.Size(239, 196);
       pSupp.Location = new Point(152, 173);
       pSupp.Name = "pSupplier";
       pSupp.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
       this.Controls.Add(pSupp);
       pSupp.BringToFront();
       dgvSupp = new DataGridView();
       dgvSupp.AllowUserToAddRows = false;
       dgvSupp.AllowUserToDeleteRows = false;
       dgvSupp.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
       dgvSupp.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
       dgvSupp.Dock = System.Windows.Forms.DockStyle.Fill;
       dgvSupp.MultiSelect = false;
       dgvSupp.ReadOnly = true;
       dgvSupp.RowHeadersVisible = false;
       dgvSupp.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
       pSupp.Controls.Clear();
       pSupp.Controls.Add(dgvSupp);
       DataTable dt = pc.fetchRecord("VIEW", "FETCHCBSUPP", "", "", "", "", "", "");
       BindingSource source = new BindingSource();
       source.DataSource = dt;
       dgvSupp.DataSource = source;
    }

我曾尝试过这样的情况,即你拖拉,放弃数据网格,点击事件性质,不工作。

    private void dgvSupp_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        DataGridViewRow row = dgvSupp.Rows[e.RowIndex];

        txtID.Text = row.Cells["Supplier ID"].Value.ToString();
    }
问题回答

@Olivier Jacot-Descombes It worked. Thanks a lot man!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签