0

ここから次のコードを適応させました

foreach (String table in tablesToTouch)
{
    foreach (Object selecteditem in listBoxSitesWithFetchedData.SelectedItems)
    {
        site = selecteditem as String;
        hhsdbutils.DeleteSiteRecordsFromTable(site, table);
    }
}

...しかし、悲しいかな、SelectedItems メンバーは私には利用できないようです: " 「System.Windows.Forms.ListBox」には「SelectedItems」の定義が含まれておらず、「System. Windows.Forms.ListBox' が見つかりました (using ディレクティブまたはアセンブリ参照がありませんか?) "

別の提案は次のとおりです。

foreach(ListItem listItem in listBox1.Items)
{
   if (listItem.Selected == True)
   {
     . . .

...しかし、ListItem も利用できません。

同じことを達成するための回避策は何ですか?

アップデート

私ができることは少なくとも2つあります(やや不器用です):

0) Manually keep track of items selected in listBoxSitesWithFetchedData (as they are clicked) and loop through *that* list
1) Dynamically create checkboxes instead of adding items to the ListBox (getting rid of the ListBox altogether), and use the text value of checked checkboxes to pass to the "Delete" method

しかし、私はまだそれらよりも簡単な方法がなければならないと考えています.

更新 2

私はこれを行うことができます(コンパイルされます):

foreach (var item in listBoxSitesWithFetchedData.Items)
{
    hhsdbutils.DeleteSiteRecordsFromTable(item.ToString(), table);
}

...しかし、選択されたアイテムのみに作用するという問題が残っています。

更新 3

CF-Whisperer が、リストボックスの複数選択は CF (楔形文字) の暗く霧の多い迷路の世界では不可能だと言ったので、コードを次のように単純化しました。

foreach (String table in tablesToTouch)
{
    // Comment from the steamed coder:
    // The esteemed user will have to perform this operation multiple times if they want 
to delete from multiple sites              
    hhsdbutils.DeleteSiteRecordsFromTable(listBoxSitesWithFetchedData.SelectedItem.ToString(), 
        table);
}
4

1 に答える 1