问题描述
我已经制作了数据网格视图并在每一行显示数据和图像,但我的客户要求我制作展开按钮以在所选行下方显示更多图像(约16幅图像)当他在每一行上点击一个按钮或鼠标时。
如何实现这个?
提前谢谢
我的尝试:
private void datagridview1_CellClick(object sender,DataGridViewCellEventArgs e)
{
if(e.ColumnIndex == btnColumnIdx)
{
string idx = dgv_main.Rows [ e.RowIndex] .Cells [idx]。Value.ToString();
}
}
Hi,
I've already made a datagridview and show data and image in each row but my customer asked me to make expand button to show more images(about 16 images) below the selected row when he clicks a button or mouse over on each row.
How can I implement this?
Thank you in advance
What I have tried:
private void datagridview1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == btnColumnIdx)
{
string idx = dgv_main.Rows[e.RowIndex].Cells["idx"].Value.ToString();
}
}
推荐答案
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestForm1
{
public partial class Form1 : Form
{
/// <summary>
/// The binding list reference.
/// </summary>
private BindingList<MyClass> masterBindingList;
public Form1()
{
InitializeComponent();
this.Init();
}
private void Init()
{
this.masterBindingList = new BindingList<MyClass>();
this.dataGridViewMaster.DataSource = this.masterBindingList;
}
private void ButtonAddRowClick(object sender, EventArgs e)
{
var rowIndex = this.dataGridViewMaster.RowCount;
this.AddRow(rowIndex);
this.ScrollToRow(rowIndex);
}
/// <summary>
/// Add new row via the BindingList.
/// </summary>
private void AddRow(int rowIndex)
{
this.masterBindingList.Add(new MyClass { Title = "Row " + rowIndex.ToString() });
}
private void ScrollToRow(int rowIndex)
{
this.dataGridViewMaster.ClearSelection();
this.dataGridViewMaster.FirstDisplayedScrollingRowIndex = rowIndex;
this.dataGridViewMaster.Focus();
}
/// <summary>
/// Simple class with one string.
/// </summary>
public class MyClass
{
public string Title { get; set; }
}
}
}
这篇关于当用户单击或鼠标悬停在C#中时,如何在datagridview中的选定行下面添加新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!