0

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

  • When you add special keyword like `remove` use []. For e.g. `[remove]` – Sameer Jan 24 '14 at 17:05
  • Okay @Sameer Thank you, sorry –  Jan 24 '14 at 17:09
  • The second link is pointing to a Full Framework .net 4.5 example. That will not work on Windows Mobile, where only Comapct Framework up to version 3.5 is available. – josef Jan 25 '14 at 04:48

2 Answers2

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

Community
  • 1
  • 1
josef
  • 5,951
  • 1
  • 13
  • 24
-1

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);
        }
    }
mnshahab
  • 770
  • 7
  • 16
  • It looks great @user3216429 Do I need some `using`? –  Jan 24 '14 at 18:23
  • No, You don't need any more using – mnshahab Jan 24 '14 at 18:33
  • What could I do? It says: **Can not find the type or namespace name 'DataGridViewButtonColumn' (are you missing a using directive or an assembly reference?)** @mnshahab –  Jan 24 '14 at 18:38
  • Do I need a `datatable`? or something else? @mnshahab –  Jan 24 '14 at 20:01
  • You can try to do manually by create datatable. but the above code works good in my machine visual stadio 2010 – mnshahab Jan 24 '14 at 20:15
  • 1. VS201 is not able to do Windows Mobile (SmartDevice) projects. 2. The DataGridViewButtonColumn is not available in Compact Famework. – josef Jan 25 '14 at 04:45
  • But properties like `.CurrentRow`, `.Rows` and `.Columns` are not available @mnshahab, What could I do? @josef –  Jan 27 '14 at 04:27