我期待在C#winforms应用程序中创建可编辑的ListView,其中用户可以双击单元格以更改其内容。如果有人能够提供一些指导和/或示例,那将是很棒的。我不打算使用任何商业产品。可编辑列表查看
可编辑列表查看
回答
你在问错误的问题:)
ListView不是正确的控件。使用DataGridView控件。它可以配置为看起来就像一个ListView,但它支持就地编辑单元格。
这是一个意见问题。 DataGridView并不总是适合使用场景或提供所需的外观。但是,这是一个可能的选择,取决于OP的目标。 – 2009-04-30 19:33:42
您无法使用DataGridView执行分组视图。再加上一系列只有ListView支持的其他功能。 – code4life 2011-04-08 22:22:39
从它的声音中,您可能想要考虑使用DataGridView。
这是一篇WPF文章。这是我们期望的,还是我们在这里直观的WinForms?标签指示WinForms。 – 2009-04-30 20:07:21
一个ObjectListView会做正是等等。它是一个正常的.NET ListView的包装。它是开源的。
它的网站上有一个Getting Started帮助你开始,以及一整页专门cell editing
感谢您的回复。这个自定义控件看起来很有趣,但对于我正在尝试做的事情可能会过度。尽管如此,我仍会试验一下。 – 2009-05-13 15:41:38
的DataGridView是你的朋友 SourceGrid是替代
您可以使用ListView控件的DoubleClick事件,当它被调用时,您将打开一个新表单,用户可以为所选项目输入一个新值。然后,当用户按下确定后,您将编辑特定项目的值以使用户输入的内容。
您可以使用DataTemplate指定该列包含文本框(如果可编辑)或文本块(如果不可编辑),然后将文本框绑定到源对象集合中的类属性,该属性绑定到您的列表视图的项目源。
<Window.Resources>
<ResourceDictionary>
<DataTemplate x:Key="NameHeader">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Name" VerticalAlignment="Center" Margin="10,0,0,0" />
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="NameCell">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Path=Name}" VerticalAlignment="Center" Margin="10,0,0,0" />
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</Window.Resources>
<Grid>
<ListView x:Name="lvwList" Height="200" VerticalAlignment="Top" ItemsSource="{Binding Path=SourceObjectCollection}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" HeaderTemplate="{StaticResource NameHeader}" CellTemplate="{StaticResource NameCell}" Width="140" />
</GridView>
</ListView.View>
</ListView>
</Grid>
尼克Hanshaw
我最近遇到了这个问题。从Simon Gillbee得知,可以将DataGridView配置成很像ListView的形式后,我寻找了一个合理的解决方案来实现这一点。以下代码适合我。 Source here。
class GridLineDataGridView : DataGridView
{
public GridLineDataGridView()
{
this.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
int rowHeight = this.RowTemplate.Height;
int h = this.ColumnHeadersHeight + rowHeight * this.RowCount;
int imgWidth = this.Width - 2;
Rectangle rFrame = new Rectangle(0, 0, imgWidth, rowHeight);
Rectangle rFill = new Rectangle(1, 1, imgWidth - 2, rowHeight);
Rectangle rowHeader = new Rectangle(2, 2, this.RowHeadersWidth - 3, rowHeight);
Pen pen = new Pen(this.GridColor, 1);
Bitmap rowImg = new Bitmap(imgWidth, rowHeight);
Graphics g = Graphics.FromImage(rowImg);
g.DrawRectangle(pen, rFrame);
g.FillRectangle(new SolidBrush(this.DefaultCellStyle.BackColor), rFill);
g.FillRectangle(new SolidBrush
(this.RowHeadersDefaultCellStyle.BackColor), rowHeader);
int w = this.RowHeadersWidth - 1;
for (int j = 0; j < this.ColumnCount; j++)
{
g.DrawLine(pen, new Point(w, 0), new Point(w, rowHeight));
w += this.Columns[j].Width;
}
int loop = (this.Height - h)/rowHeight;
for (int j = 0; j < loop + 1; j++)
{
e.Graphics.DrawImage(rowImg, 1, h + j * rowHeight);
}
}
}
从DataGridView
只是继承和覆盖OnPaint
方法。
您可以更改控件的各种属性以满足您的需求和偏好。
对于那些需要帮助将自定义控件合并到他们的项目中看看here。
是的,使用DataGridView。
不仅可以编辑单元格,而且如果您声明了一个通用列表,其中T是要在网格中显示的类,那么可以设置DataSource =列表,并且在编辑gridview时实际编辑列表自动!
- 1. Linq编辑列表查看
- 2. iPhone:查看/编辑/列表控制器
- 3. 隐藏/查看编辑查看表格
- 4. 查看未编辑
- 5. Postgres可编辑联盟查看
- 6. jqGrid编辑/查看表单组合
- 7. 宏编辑/查看保护
- 8. 编辑和查看饼干
- 9. ASP.NET列表查看搜索和编辑不工作
- 10. GAE数据存储查看器 - 编辑列表
- 11. 编辑文本过滤/搜索列表查看
- 12. WPF可编辑列表视图与可编辑组合框
- 13. 使用Mindmup可编辑表格使某些列不可编辑
- 14. primefaces:可编辑数据表中的不可编辑列
- 15. jQuery可编辑/可排序列表
- 16. jQuery可编辑/不可编辑表格
- 17. Android搜索可检查列表查看
- 18. 编辑列表
- 19. 使文本字段可查看但不可编辑
- 20. 查看列表
- 21. 需要“可编辑的下拉列表”
- 22. Angularjs中的可编辑列表
- 23. ASP.NET MVC“可编辑”列表框
- 24. 绑定儿童的可编辑列表
- 25. 首选项中的可编辑列表
- 26. Django可编辑列表视图
- 27. 我们如何让列表可编辑?
- 28. 可编辑的jQuery插件列表?
- 29. 可编辑的WPF列表框
- 30. TcL - 列表编辑
你的问题可能在这里得到解答:[C#:如何编辑在ListView项目和子项目?] [1] [1]:http://stackoverflow.com/questions/471859/ c-how-do-you-edit-items-and-subitems-in-a-listview – 2012-07-10 11:08:40
我不同意我们不应该看像DataGridView,ObjectListView这样的ListView替代品,或者甚至像[this]这样的商业解决方案(http:// 10tec.com/articles/editable-listview-replacement.aspx),这是足够便宜的。使用文本框编辑器在ListView项目/子文件中实现众所周知的方法有许多缺点,您必须自己解决。例如,您需要提供一个良好的键盘界面来编辑子项目,文本框应该与ListView一起滚动,等等。使用良好的第三方解决方案可以节省数小时的编码,最终您甚至可以赚取更多。 – TecMan 2016-07-28 11:48:57