How to add a new column to delete a Datagrid's row, Windows mobile

自作多情 提交于 2019-12-12 05:49:05

问题


I am developing an application for windows mobile in C# (visual studio 2008) and sql server 2008

I use a "select" to display columns in a DataGrid:

                SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM DATOST", conn);
                da.Fill(ds, "DATOST");
                dtgLista.DataSource = ds.Tables[0].DefaultView;

and it shows something like this

What I'm trying to do is to add a new column with the word remove and when it be selected delete the row.

I tried with this

--- and more links I can't write because i need at least 10 reputation to post more than 2 links---

But My app doesn´t work

Any easier idea please?

Thank You


回答1:


Compact Framework, which the .net runtime running on Windows Mobile, does not support button or other elements within a datagrid. Only EditBox is supported by default.

There are already questions and answers on how to add a button or checkBox to a compact framework datagrid here at stackoverflow:

How to add a button to a compact framework DataGrid?

Attach button to column datagrid in C# Compact Framework .Net 2.0

and

display images in datagrid with Compact Framework

and at other sides like: http://social.msdn.microsoft.com/Forums/en-US/caee833d-f0ac-496f-b13c-b87116450f39/how-to-add-a-button-in-a-datagrid

The solution is to add a custom paint handler for datacells.

There are also commercial extended datagrid controls available that support more than only EditBox: for example Resco SmartDrid control: article at codeproject. I am sure there are other vendors too. Just use a internet search "compact framework datagrid add button".




回答2:


You can add delete bottun to 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);

and then write event handler to remove the selected row

    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);
        }
    }


来源:https://stackoverflow.com/questions/21338171/how-to-add-a-new-column-to-delete-a-datagrids-row-windows-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!