gridview内嵌ButtonEdit遇到的问题
//创建ButtonEdit
DevExpress.XtraEditors.Repository.RepositoryItem buttonedit = new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit();
//为根据列明为griview的列动态添加ButtonEdit
private void FrmPresent_Load(object sender, EventArgs e)
{
foreach (GridColumn gridColumn in gridView1.Columns)
{
if (gridColumn.FieldName != "Name" && gridColumn.FieldName != "Age")
{
gridColumn.ColumnEdit = buttonedit;
}
}
buttonedit.Click += new EventHandler(buttonedit_Click);
}
//在这个事件里想把选择的文件名显示在gridview的单元格中
private void buttonedit_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel文件(*.xls,*.xlsx)|*.xls;*.xlsx";
openFileDialog.Title = "请选择文件";
if (openFileDialog.ShowDialog() == DialogResult.Cancel)
{
return;
}
我想应该是在这里取得buttonedit.Text=openFileDialog.FileName
可是提示此时buttonedit没有Text的这个属性,行完成这个功能应该怎么做呢?
}
------解决方案--------------------你显示在单元格中
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.FocusedColumn,openFileDialog.FileName);
就可以了,不需要找到buttonedit的Text