2

C#2008SP1。

datagridviewで現在選択されている行から行を削除しています。

タイプされたデータセットを使用していて、datagridviewはバインディングソースにバインドされています。

しかし、私のテクニックはうまくいくのに、最高ではないと思います。

アドバイスをありがとう、

 DataRow[] drDelete;
            // Get the value of the PK from the currently selected row
            DataRowView drv = (DataRowView)bsAddressBook.Current;
            int index = Convert.ToInt16(drv[0]);

            // Find the actual data row from the primary key and delete the row
            drDelete = dsCATDialer.AddressBook.Select(string.Format("ID = '{0}'", index));
            dsCATDialer.AddressBook.Rows.Remove(drDelete[0]);
4

2 に答える 2

5

BindingSource を使用して直接削除することもできます。

bsAddressBook.RemoveCurrent();
于 2009-05-15T08:00:46.457 に答える
3

DataRowView の Row プロパティを使用してこれを短縮できると思います。

// Get the value of the PK from the currently selected row
DataRowView drv = (DataRowView)bsAddressBook.Current;

DataRow drDelete = drv.Row;
dsCATDialer.AddressBook.Rows.Remove(drDelete);
于 2009-05-15T07:51:29.180 に答える