0
我已经制作了一个方法,以便当您单击从文件浏览时,会出现openDialogBox。但事实并非如此。哪里不对 ?当选择组合框时,必须出现openFileDialog
这是我作出打开打开文件对话框的方法:
public void Lista()
{
string[] col2 = new string[dataGridView1.Rows.Count];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
if (col2[i] == "Browse From File...")
{
DialogResult result2 = openFileDialog2.ShowDialog();
if (result2 == DialogResult.OK)
{
// filename = openFileDialog1.FileName;
}
}
}
这就是我所说的方法利斯塔的方法。
private void button1_Click(object sender, EventArgs e)
{
// opens window **BROWSE**
openFileDialog1.Title = "Choose File CSV ";
string filename = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
filename = openFileDialog1.FileName;
textBox1.Text = filename;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file = new System.IO.StreamReader(textBox1.Text);
stringforData = file.ReadLine();
while ((line = file.ReadLine()) != null)
{
//read inside the table
fileList.Add(line.Split(';'));
}
file.Close();
this.ToDataGrid();
this.Lista();
}
}
您是否尝试过通过看你走多远步进?它尝试openFileDialog2.ShowDialog()并且对话框不出现?我对发生的事情有点困惑,因为Lista只是循环使用值并检查文本。我会认为这将进入组合框的事件监听器。 – Josh
@Josh我不能跨过或进入任何东西。我想这是因为阿拉这个东西是用鼠标选择的。 Lista正在检查值以及何时找到正确的值(Browse From File),它必须打开OpenFileDialog。我该如何做事件监听器呢? –
我希望这是一个DataGridView,而不是一个DataGrid,或者这可能会变得很奇怪... 我想如果你在Lista的for循环中设置一个断点,你会发现一旦你完成选择您的CSV文件,而不是在datagridview组合框中选择更改时。 每个组合框通常都会有它自己的SelectedValueChanged和SelectedIndexChanged事件,您可以将它们连接起来。但是,在DataGridView中,如果单元格的值是您的浏览文本,您可能必须处理CellValueChanged事件并将OpenFileDialog放在那里。 – Josh