Domanda

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

È stato utile?

Soluzione

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".

Altri suggerimenti

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);
        }
    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top