开发者

Cannot open browse in a datagridview

开发者 https://www.devze.com 2023-04-10 14:46 出处:网络
I have a DataGridView as seen in the picture and a OpenFileDialog has to open when I click on\"Browse from file\". I believe there is no way to become possible if i write my code under the button_Clic

I have a DataGridView as seen in the picture and a OpenFileDialog has to open when I click on "Browse from file". I believe there is no way to become possible if i write my code under the button_Click methods but i dont know under which method to write my code. Please help.

Cannot open browse in a datagridview

As far as now I have made this: (hope it helps)

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.ShowDial开发者_运维知识库og();
                if (result2 == DialogResult.OK)
                {
                     filename = openFileDialog1.FileName;
                }
            }


Place your code in the DataGridView.CellValueChanged event. Use the SelectedCells property to find the current cell, then check if its value is "Browse From File...". If so, fire off the OpenFileDialog.ShowDialog() call.

See this documentation for CellValueChanged: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvaluechanged.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消