繁体   English   中英

使属性在datagridview usercontrol中可用C#

[英]Making properties available in datagridview usercontrol c#

几天以来,我开始使用分页对datagridview进行编码。 分页本身可以正常工作并计算良好。 但是现在我遇到了一个问题,我需要定制的用户控件中不可用的属性。

为了能够使用我自己制作的用户控件,在将其导出到.dll文件(用户控件)时,我需要以下属性可用:

  • 列属性(datagridview.Columns)
  • CurrentRow.Index属性(datagridview.CurrentRow.Index)
  • Rows.Count属性(datagridview.Rows.Count)
  • Rows.Cells.Value(datagridview.Rows [counter] .Cells [cellcounter] .value)
  • Column.width属性(datagridview.Column.Width)

有人可以帮我一路做/举例吗? 我不知道该如何进行。

我有一个我也需要的属性,所以我想这可以作为一个例子:)

public void SetColumns( string columnName)
{
    dataGridView.Columns[columnName].Visible = false;
}

简而言之:如何通过在datagridview中进行编码来使这些属性在其他项目中可用? 这将是一个用户控件。

谢谢你,恩特

答案将取决于您到底需要什么。
第一种情况将涉及向用户公开DataGridView本身。 在您的UserControl中:

private DataGridView _dataGridView1;

//Lets use a readonly property for this one
//Be careful, readonly property doesn't mean you can't modify the values inside!
public DataGridView UserControlDataGridView 
{
    get
    {
        return _dataGridView1;
    } 
}

然后,您将可以控制其他项目中的DataGridView。

如果您不想向用户公开DataGridView,则需要为所需的每个项目创建一个属性。

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM