如何添加Contols动态的DataGridView中排在Windows窗体应用程序? [英] How to add Contols Dynamically in DataGridView Row in Windows Form Application?
问题描述
我有不同的控制输入一个DataGridView中的每一行现在我想根据该控件类型是有可能每行中创建的控制? 如果是的话如何?
I have a DataGridView with Different Control Type in Each row now i want to create control in each row according to that Control Type Is it Possible? if Yes then How ?
推荐答案
您可以在您的网格显示OnRowDatabound加控制,那么您可以在控制你的行
You can add control on the OnRowDatabound of your grid, then you can a controls to your row
要一个控件添加到电池中使用
To add a control to a cell use
void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row as GridViewRow;
if (row != null)
{
MyObject myObject = new MyObject();
row.Cells[0].Controls.Add(myObject);
}
}
要一个控件添加到整行使用
To add a control to the entire row use
void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridViewRow row = e.Row as GridViewRow;
if (row != null)
{
MyObject myObject = new MyObject();
row.Controls.Add(myObject);
}
}
看一看这里的窗户形成网格
Have a look here for the windows forms Grid
您可以通过继承的DataGridViewColumn类的派生类或提供自定义的外观,行为,或托管控件创建自己的列类。欲了解更多信息,请参阅如何:自定义单元格和列在Windows通过扩展他们的行为和窗体DataGridView控件外观
You can create your own column class by inheriting the DataGridViewColumn class or any of its derived classes to provide custom appearance, behavior, or hosted controls. For more information, see How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance
http://msdn.microsoft。 COM / EN-US /库/ bxt3k60s%28V = VS.80%29.aspx
如何:自定义单元格和列在Windows通过扩展他们的行为和外观
窗体DataGridView控件
http://msdn.microsoft.com/en -us /库/ 7fb61s43%28V = VS.80%29.aspx
How to: Customize Cells and Columns in the Windows Forms DataGridView Control by Extending Their Behavior and Appearance
http://msdn.microsoft.com/en-us/library/7fb61s43%28v=vs.80%29.aspx
这篇关于如何添加Contols动态的DataGridView中排在Windows窗体应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!