如何在C#中的DataGridView中添加Picturebox控件
private void InitializeComponent()
{
dataGrid = new DataGridView();
dataGrid.DataSource = this._lstWorklet;
dataGrid.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(dataGrid_DataBindingComplete);
}
private void dataGrid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
PictureBox _btnView = new PictureBox();
_btnView.Size = new System.Drawing.Size(24, 24);
_btnView.BackgroundImage = ProcessingDataModel._viewImg;
_btnView.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
_btnView.Cursor = System.Windows.Forms.Cursors.Hand;
_btnView.Click += new System.EventHandler(this.btnViewRecording_click);
System.Windows.Forms.ToolTip _toolTipView = new System.Windows.Forms.ToolTip();
_toolTipView.SetToolTip(_btnView, "View Recording");
PictureBox _btnDelete = new PictureBox();
_btnDelete.Size = new System.Drawing.Size(24, 24);
_btnDelete.BackgroundImage = ProcessingDataModel._deleteImg;
_btnDelete.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
_btnDelete.Cursor = System.Windows.Forms.Cursors.Hand;
_btnDelete.Click += new System.EventHandler(this.btnDeleteRecording_click);
System.Windows.Forms.ToolTip _toolTipDelete = new System.Windows.Forms.ToolTip();
_toolTipDelete.SetToolTip(_btnDelete, "Delete Recording");
dataGrid.Columns[3].Name = "Action";
dataGrid.Columns[3].HeaderText = "Action";
dataGrid.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
for (int i = 0; i <= dataGrid.Rows.Count; i++)
{
dataGrid.Rows[i].Cells[3].Controls.Add(_btnView);
dataGrid.Rows[i].Cells[3].Controls.Add(_btnDelete);
}
}
我会在(datagrid.rows [i] .cells [3] .controls.add(_btnview))上遇到错误的错误,例如'datagridViewCell'不包含“控件”的定义,没有可访问的扩展方法'可以找到控制“接受“ datagridviewcell”类型的第一个参数”(您是否缺少使用指令或汇编引用?) 因此,请帮助我将platuerbox添加到Windows应用程序的DataGridView中的列中。
private void InitializeComponent()
{
dataGrid = new DataGridView();
dataGrid.DataSource = this._lstWorklet;
dataGrid.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(dataGrid_DataBindingComplete);
}
private void dataGrid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
PictureBox _btnView = new PictureBox();
_btnView.Size = new System.Drawing.Size(24, 24);
_btnView.BackgroundImage = ProcessingDataModel._viewImg;
_btnView.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
_btnView.Cursor = System.Windows.Forms.Cursors.Hand;
_btnView.Click += new System.EventHandler(this.btnViewRecording_click);
System.Windows.Forms.ToolTip _toolTipView = new System.Windows.Forms.ToolTip();
_toolTipView.SetToolTip(_btnView, "View Recording");
PictureBox _btnDelete = new PictureBox();
_btnDelete.Size = new System.Drawing.Size(24, 24);
_btnDelete.BackgroundImage = ProcessingDataModel._deleteImg;
_btnDelete.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
_btnDelete.Cursor = System.Windows.Forms.Cursors.Hand;
_btnDelete.Click += new System.EventHandler(this.btnDeleteRecording_click);
System.Windows.Forms.ToolTip _toolTipDelete = new System.Windows.Forms.ToolTip();
_toolTipDelete.SetToolTip(_btnDelete, "Delete Recording");
dataGrid.Columns[3].Name = "Action";
dataGrid.Columns[3].HeaderText = "Action";
dataGrid.Columns[3].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
for (int i = 0; i <= dataGrid.Rows.Count; i++)
{
dataGrid.Rows[i].Cells[3].Controls.Add(_btnView);
dataGrid.Rows[i].Cells[3].Controls.Add(_btnDelete);
}
}
I am getting error in for loop on (dataGrid.Rows[i].Cells[3].Controls.Add(_btnView)) like 'DataGridViewCell' does not contain a definition for 'Controls' and no accessible extension method 'Controls' accepting a first argument of type 'DataGridViewCell' could be found (are you missing a using directive or an assembly reference?)
So please help me about adding the Picturebox to the column in datagridview for windows application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论