C# 如何添加新列以删除Datagrid';s行,Windows mobile
我正在C# 如何添加新列以删除Datagrid';s行,Windows mobile,c#,datagrid,windows-mobile,C#,Datagrid,Windows Mobile,我正在C(VisualStudio2008)和SQLServer2008中为windows mobile开发一个应用程序 我使用“选择”来显示数据网格中的列: SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM DATOST", conn); da.Fill(ds, "DATOST"); dtgLista.DataSource = ds.
C
(VisualStudio2008
)和SQLServer2008
中为windows mobile开发一个应用程序
我使用“选择”来显示数据网格中的列:
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM DATOST", conn);
da.Fill(ds, "DATOST");
dtgLista.DataSource = ds.Tables[0].DefaultView;
它显示了类似于
我想做的是添加一个新的列,其中包含单词remove
,当它被选中时,删除该行
我试过了
---还有更多我不能写的链接,因为我需要至少10个声誉才能发布2个以上的链接--
但是我的应用程序不工作
有更简单的想法吗?
谢谢您可以将delete bottun添加到datagridview
SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM DATOST", conn);
da.Fill(ds, "DATOST");
DataGridViewButtonColumn col = new DataGridViewButtonColumn();
col.UseColumnTextForButtonValue = true;
col.Text = "REmove";
col.Name = "MyButton";
dataGridView1.Columns.Add(col);
dtgLista.DataSource = ds.Tables[0].DefaultView;
this.dataGridView1.CellContentClick += new DataGridViewCellEventHandler(this.CellContentClick);
然后编写事件处理程序以删除所选行
private void CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//make sure click not on header and column is type of ButtonColumn
if (e.RowIndex >= 0 && ((DataGridView)sender).Columns[e.ColumnIndex].GetType() == typeof(DataGridViewButtonColumn))
{
dataGridView1.Rows.RemoveAt(e.RowIndex);
}
}
在Windows Mobile上运行的.net运行时不支持datagrid中的按钮或其他元素的Compact Framework。默认情况下仅支持EditBox
关于如何在stackoverflow向compact framework datagrid添加按钮或复选框,已经有很多问题和答案:
及
在其他方面,比如:
解决方案是为数据单元添加自定义绘制处理程序
还有一些商业扩展datagrid控件可供使用,它们不仅支持EditBox:例如Resco SmartDrid控件:at codeproject。我相信还有其他供应商。只需使用internet搜索“compact framework datagrid添加按钮”。当您添加特殊关键字时,如remove
use[]。例如,[remove]
好的@Sameer谢谢,对不起,第二个链接指向完整的Framework.net 4.5示例。这在Windows Mobile上不起作用,因为只有3.5版以上的Comapct Framework可用。它看起来很棒@user3216429我需要一些使用
的吗?不,你不需要更多的使用我能做什么?它说:找不到类型或命名空间名称“DataGridViewButtonColumn”(是否缺少using指令或程序集引用?)@mnshahabDo我需要一个数据表?还是别的什么@您可以尝试通过创建datatable手动执行此操作。但是上面的代码在我的机器visual stadio 2010中运行良好