Dear Admins.
Using the Following code to open the FileDialog.
private
void
btnBrowse_Click(
object
sender, EventArgs e)
{
RadOpenFileDialogForm openFileDialog =
new
RadOpenFileDialogForm();
openFileDialog.ShowHiddenFiles =
false
;
openFileDialog.FilterIndex = 1;
openFileDialog.Filter =
"GIF (*.gif)|*.gif| "
+
"Bitmap Files (*.bmp)|*.bmp|"
+
"JPEG (*.jpg; *.jpeg)|*.jpg;*.jpeg|"
;
openFileDialog.RestoreDirectory =
true
;
DialogResult dr = openFileDialog.ShowDialog();
if
(dr == DialogResult.OK)
{
string
filePath = openFileDialog.FileName;
}
}
But every time when dialog box open Third Option from the Filter List is selected.
I want to select default first option.
5 Answers, 1 is accepted
Hi Muhammad,
You can use the Shown event to set the filter manually. Here is the code:
private void RadButton1_Click(object sender, EventArgs e)
{
RadOpenFileDialog openFileDialog = new RadOpenFileDialog();
openFileDialog.ShowHiddenFiles = false;
openFileDialog.FilterIndex = 1;
openFileDialog.Filter = "GIF (*.gif)|*.gif| " +
"Bitmap Files (*.bmp)|*.bmp|" +
"JPEG (*.jpg; *.jpeg)|*.jpg;*.jpeg|";
openFileDialog.RestoreDirectory = true;
openFileDialog.OpenFileDialogForm.Shown += OpenFileDialogForm_Shown;
DialogResult dr = openFileDialog.ShowDialog();
if (dr == DialogResult.OK)
{
string filePath = openFileDialog.FileName;
}
}
private void OpenFileDialogForm_Shown(object sender, EventArgs e)
{
var form = sender as RadOpenFileDialogForm;
var filterDropDown = form.Controls[0].Controls[6] as RadDropDownList;
filterDropDown.SelectedIndex = 0;
}
I hope this helps. Should you have any other questions, do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
When Use this line
openFileDialog.OpenFileDialogForm.Shown += OpenFileDialogForm_Shown;
this error popup.
'RadOpenFileDialogForm' does not contain a definition for 'OpenFileDialogForm' and no accessible extension method 'OpenFileDialogForm' accepting a first argument of type 'RadOpenFileDialogForm' could be found (are you missing a using directive or an assembly reference?)
openFileDialog.OpenFileDialogForm.Shown += OpenFileDialogForm_Shown;
this error popup.
'RadOpenFileDialogForm' does not contain a definition for 'OpenFileDialogForm' and no accessible extension method 'OpenFileDialogForm' accepting a first argument of type 'RadOpenFileDialogForm' could be found (are you missing a using directive or an assembly reference?)
Hello Muhammad,
I have attached my test project. Could you please check it and let me know how it differs from your real setup?
Are you inheriting the dialog class and applying the changes in it?
I am looking forward to your reply.
Regards,
Dimitar
Progress Telerik