我正在尝试验证用户在可编辑的网格视图中输入的内容。我使用事件 CellLeave 来验证输入,如下所示:
private void membersGrid_CellLeave(object sender, DataGridViewCellEventArgs e)
{
// Datatable that will hold the schema for the Members table
DataTable dtMeta;
// SqlDataAdapter is already filled and is now used to get the metadata
daAllMembers.FillSchema(dtMeta, SchemaType.Source);
// Define a type instance of the current column from the metadata table dtMeta
System.Type cellType = dtMeta.Columns[e.ColumnIndex].DataType;
// Get an object from the editted cell
Object objCellValue = membersGrid[e.ColumnIndex, e.RowIndex].Value;
// This is where i'm stuck, how can I do this?
cellType.TryParse(objCellValue);
}
我希望你明白我想要做什么。我基本上想尝试将对象解析为该表的元数据中定义的类型。
任何帮助表示赞赏;)