Default Filename SaveFileDialog

前端 未结 5 2163
时光取名叫无心
时光取名叫无心 2020-12-18 19:39

I would like to create SaveFileDialog with default file name from value DataGridViewCells

So far I tried

priva         


        
5条回答
  •  甜味超标
    2020-12-18 20:16

    The problem is that you need to use:

    myDataGridView.SelectedCells[0].Value.ToString();
    

    instead of

    myDataGridView.SelectedCells[2].Value.ToString();
    

    Until you don't select 3 or more cells with mouse or whatsoever. You can index like [2]

    private void buttonSave_Click(object sender, EventArgs e) 
    {
        SaveFileDialog saveFile = new SaveFileDialog();
        saveFile.FileName = myDataGridView.SelectedCells[0].Value.ToString();
        saveFile.ShowDialog();
    }
    

    Does this work for you?

提交回复
热议问题