0
我正在創建一個程序,該程序將提供一個前端以從服務器位置打開文件,而無需導航到服務器位置。該程序具有打開某些類別列表的按鈕,然後使用單個按鈕打開列表中當前選定項目的文件。識別按鈕中的可見列表
我目前的問題是能夠識別哪個ListBox當前在視圖中,以便程序知道哪個列表用作打開正確文件的參考。
有沒有辦法創建一個名爲「List」的「對象」,然後將列表框分配給它並引用它?它似乎不喜歡我所做的。
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);
}