私は、サーバーの場所に移動することなく、サーバーの場所からファイルを開くためのフロントエンドを提供するプログラムを作成しています。プログラムには、特定のカテゴリのリストを開くボタンと、リストから現在選択されているアイテムのファイルを開くボタンがあります。ボタンの目に見えるリストを確認する
私の現在の問題は、どのリストが正しいファイルを開くための参照として使用するかを知るために、現在どのリストボックスが表示されているのかを特定することができることです。
"リスト"と呼ばれる "オブジェクト"を作成し、それにリストボックスを割り当てて参照する方法はありますか?それは私がやったことが好きではないようです。
object ListBox;
int IdCheck = 0;
string DriveLoc;
private void ButtAirInfo_Click(object sender, EventArgs e)
{
GBAirInfo.Visible = true;
GBAir.Visible = false;
ListBox = LBAirInfo; //Here is where I load the List on to the screen, then
//assign the list to the object ListBox
}
private void button2_Click(object sender, EventArgs e)
{
using (connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Files", connection))
{
DataTable FilesTable = new DataTable();
adapter.Fill(FilesTable);
if (ListBox.SelectedIndex == -1)
MessageBox.Show("No Items selected");
else
IdCheck = ListBox.SelectedIndex;
DriveLoc = (FilesTable.Rows[IdCheck]["Location"].ToString());
if (DriveLoc == "")
MessageBox.Show("Item does not have a location");
else
System.Diagnostics.Process.Start(@DriveLoc);
}