我有一个WFA,可用于即时恢复数据库。现在,我有一个列表框,显示目录中的所有备份,但它也包含我要访问的文件夹。这是列表框的代码:
private void PopulateListBox()
{
try
{
var dinfo = new DirectoryInfo(@"C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup");
var files = dinfo.GetFiles("*.bak");
foreach (var file in files)
{
listBox1.Items.Add(file.Name);
}
}
catch (Exception)
{
MessageBox.Show("The application could not find the directory to populate the List Box.");
}
}
目前,我有一个组合框,用于显示“备份”中的不同文件夹:
private void PopulateComboBox()
{
string[] directory = Directory.GetDirectories(@"C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup");
foreach (string folder in directory)
{
comboBox1.Items.Add(folder);
}
}
我想做的是,当我从组合框中单击另一个目录时,更改了列表框的内容。我创建了一个方法来实现我想做的事情,但是我不确定如何编写它。
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listbox1.Clear()
//rest of the code would go here
}
如何根据组合框中的选择内容在列表框中显示每个目录的内容?
我更像是WPF的家伙,但是我很确定它在这里的工作方式相同。
您要处理“ SelectionChanged”事件之一(SelectedIndexChanged,SelectedValueChanged或SelecitonChangeCommitted),然后在处理程序中放入代码以检查组合框中选中的项目,然后根据该选择重新填充列表框。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句