我试图在DevExpress网格中单击按钮时显示图片。网格是动态创建的。它只要我试图让其中图像名称存储我收到以下错误的单元格的值显示在网格精细的数据,但:无法从动态创建的Devexpress Grid中获取rowindex
"Index was outside the bounds of the array."
下面是我到目前为止有:
public GridControl CreateGrid(string[] ColNames, string[] FieldNames, string SqlData, params object[] pars) {
grid = new GridControl();
view = new GridView();
grid.Dock = DockStyle.Fill;
grid.ViewCollection.Add(view);
grid.MainView = view;
view.GridControl = grid;
view.OptionsView.ShowGroupPanel = false;
view.OptionsView.ShowAutoFilterRow = false;
view.OptionsBehavior.Editable = true;
view.OptionsBehavior.ReadOnly = true;
view.OptionsSelection.MultiSelect = true;
view.OptionsSelection.MultiSelect = true;
for(int i = 0; i < ColNames.Length; i++) {
GridColumn column = view.Columns.Add();
column.Caption = ColNames[i];
column.FieldName = FieldNames[i];
column.Visible = true;
}
table = GlobalDBCTM.DataTableForSql(SqlData, pars);
grid.DataSource = table;
grid.BringToFront();
grid.Tag = view;
RepositoryItemButtonEdit btnPhoto = new RepositoryItemButtonEdit();
btnPhoto.AutoHeight = false;
btnPhoto.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
btnPhoto.Buttons[0].Image = Properties.Resources.copy;
btnPhoto.TextEditStyle = TextEditStyles.HideTextEditor;
btnPhoto.ButtonClick += new ButtonPressedEventHandler(btnPhoto_ButtonClick);
view.Columns[8].ColumnEdit = btnPhoto;
grids.Add(grid);
return grid;
}
void btnPhoto_ButtonClick(object sender, EventArgs e) {
var id = view.GetSelectedRows()[0];
var photopath = (string)view.GetRowCellValue(id, view.Columns["PhotoPath"]);
var path = Globals.PhotoRootPath + "\\" + photopath + ".jpg";
System.Diagnostics.Process.Start(path);
}
的WinForms或WebForms的??? – 2012-08-16 08:22:39