@@ -331,7 +331,7 @@ public string Filter
331
331
332
332
[ Browsable ( false ) ]
333
333
[ XmlIgnore ]
334
- public Func < Record , object [ ] > CustomValuesProvider ;
334
+ public Func < object , Record , CustomValues > CustomValuesProvider ;
335
335
336
336
[ Browsable ( false ) ]
337
337
[ XmlIgnore ]
@@ -416,31 +416,31 @@ private void SetValue(Record record, object obj, object value)
416
416
record . SetValue ( obj , value ) ;
417
417
}
418
418
419
- private ComboView CreateCustomValuesEditor ( Record record , object [ ] customValues , bool hasSetter )
419
+ private ComboView CreateCustomValuesEditor ( Record record , CustomValues customValues , bool hasSetter )
420
420
{
421
421
var propertyType = record . Type ;
422
422
var value = record . GetValue ( _object ) ;
423
423
424
424
var cv = new ComboView ( ) ;
425
- foreach ( var v in customValues )
425
+ foreach ( var v in customValues . Values )
426
426
{
427
427
var label = new Label
428
428
{
429
- Text = v . ToString ( ) ,
430
- Tag = v
429
+ Text = v . Name ,
430
+ Tag = v . Value
431
431
} ;
432
432
433
433
cv . Widgets . Add ( label ) ;
434
434
}
435
435
436
- cv . SelectedIndex = Array . IndexOf ( customValues , value ) ;
436
+ cv . SelectedIndex = customValues . SelectedIndex ;
437
437
if ( hasSetter )
438
438
{
439
439
cv . SelectedIndexChanged += ( sender , args ) =>
440
440
{
441
- var item = cv . SelectedIndex != null ? customValues [ cv . SelectedIndex . Value ] : null ;
441
+ var item = cv . SelectedIndex != null ? customValues . Values [ cv . SelectedIndex . Value ] . Value : null ;
442
442
SetValue ( record , _object , item ) ;
443
- FireChanged ( propertyType . Name ) ;
443
+ FireChanged ( record . Name ) ;
444
444
} ;
445
445
}
446
446
else
@@ -1147,19 +1147,25 @@ private void FillSubGrid(ref int y, IReadOnlyList<Record> records)
1147
1147
var propertyType = record . Type ;
1148
1148
1149
1149
Proportion rowProportion ;
1150
- object [ ] customValues = null ;
1150
+ CustomValues customValues = null ;
1151
+
1152
+ var needsSubGrid = false ;
1151
1153
if ( ( valueWidget = CustomWidgetProvider ? . Invoke ( record , _object ) ) != null )
1152
1154
{
1153
1155
1154
1156
}
1155
- else if ( CustomValuesProvider != null && ( customValues = CustomValuesProvider ( record ) ) != null )
1157
+ else if ( CustomValuesProvider != null && ( customValues = CustomValuesProvider ( _object , record ) ) != null )
1156
1158
{
1157
- if ( customValues . Length == 0 )
1159
+ if ( customValues . Values . Length == 0 )
1158
1160
{
1159
1161
continue ;
1160
1162
}
1161
1163
1162
1164
valueWidget = CreateCustomValuesEditor ( record , customValues , hasSetter ) ;
1165
+ if ( value != null && ! value . GetType ( ) . IsPrimitive && value . GetType ( ) != typeof ( string ) )
1166
+ {
1167
+ needsSubGrid = true ;
1168
+ }
1163
1169
}
1164
1170
else if ( propertyType == typeof ( bool ) )
1165
1171
{
@@ -1176,7 +1182,6 @@ private void FillSubGrid(ref int y, IReadOnlyList<Record> records)
1176
1182
else if ( propertyType . IsNumericType ( ) ||
1177
1183
( propertyType . IsNullablePrimitive ( ) && propertyType . GetNullableType ( ) . IsNumericType ( ) ) )
1178
1184
{
1179
-
1180
1185
valueWidget = CreateNumericEditor ( record , hasSetter ) ;
1181
1186
}
1182
1187
else if ( propertyType == typeof ( string ) && record . FindAttribute < FilePathAttribute > ( ) != null )
@@ -1228,6 +1233,59 @@ private void FillSubGrid(ref int y, IReadOnlyList<Record> records)
1228
1233
#endif
1229
1234
#endif
1230
1235
else
1236
+ {
1237
+ if ( value == null )
1238
+ {
1239
+ var tb = new Label ( ) ;
1240
+ tb . ApplyLabelStyle ( PropertyGridStyle . LabelStyle ) ;
1241
+ tb . Text = "null" ;
1242
+
1243
+ valueWidget = tb ;
1244
+ } else
1245
+ {
1246
+ needsSubGrid = true ;
1247
+ }
1248
+ }
1249
+
1250
+ if ( valueWidget != null )
1251
+ {
1252
+ var name = record . Name ;
1253
+ var dn = record . FindAttribute < DisplayNameAttribute > ( ) ;
1254
+
1255
+ if ( dn != null )
1256
+ {
1257
+ name = dn . DisplayName ;
1258
+ }
1259
+
1260
+ if ( ! PassesFilter ( name ) )
1261
+ {
1262
+ continue ;
1263
+ }
1264
+
1265
+ var nameLabel = new Label
1266
+ {
1267
+ Text = name ,
1268
+ VerticalAlignment = VerticalAlignment . Center ,
1269
+ } ;
1270
+
1271
+ Grid . SetColumn ( nameLabel , 0 ) ;
1272
+ Grid . SetRow ( nameLabel , oldY ) ;
1273
+
1274
+ Children . Add ( nameLabel ) ;
1275
+
1276
+ Grid . SetColumn ( valueWidget , 1 ) ;
1277
+ Grid . SetRow ( valueWidget , oldY ) ;
1278
+ valueWidget . HorizontalAlignment = HorizontalAlignment . Stretch ;
1279
+ valueWidget . VerticalAlignment = VerticalAlignment . Top ;
1280
+
1281
+ Children . Add ( valueWidget ) ;
1282
+
1283
+ rowProportion = new Proportion ( ProportionType . Auto ) ;
1284
+ _layout . RowsProportions . Add ( rowProportion ) ;
1285
+ ++ y ;
1286
+ }
1287
+
1288
+ if ( needsSubGrid )
1231
1289
{
1232
1290
// Subgrid
1233
1291
if ( value != null )
@@ -1247,52 +1305,7 @@ private void FillSubGrid(ref int y, IReadOnlyList<Record> records)
1247
1305
1248
1306
continue ;
1249
1307
}
1250
-
1251
- var tb = new Label ( ) ;
1252
- tb . ApplyLabelStyle ( PropertyGridStyle . LabelStyle ) ;
1253
- tb . Text = "null" ;
1254
-
1255
- valueWidget = tb ;
1256
1308
}
1257
-
1258
- if ( valueWidget == null )
1259
- {
1260
- continue ;
1261
- }
1262
-
1263
- var name = record . Name ;
1264
- var dn = record . FindAttribute < DisplayNameAttribute > ( ) ;
1265
-
1266
- if ( dn != null )
1267
- {
1268
- name = dn . DisplayName ;
1269
- }
1270
-
1271
- if ( ! PassesFilter ( name ) )
1272
- {
1273
- continue ;
1274
- }
1275
-
1276
- var nameLabel = new Label
1277
- {
1278
- Text = name ,
1279
- VerticalAlignment = VerticalAlignment . Center ,
1280
- } ;
1281
- Grid . SetColumn ( nameLabel , 0 ) ;
1282
- Grid . SetRow ( nameLabel , oldY ) ;
1283
-
1284
- Children . Add ( nameLabel ) ;
1285
-
1286
- Grid . SetColumn ( valueWidget , 1 ) ;
1287
- Grid . SetRow ( valueWidget , oldY ) ;
1288
- valueWidget . HorizontalAlignment = HorizontalAlignment . Stretch ;
1289
- valueWidget . VerticalAlignment = VerticalAlignment . Top ;
1290
-
1291
- Children . Add ( valueWidget ) ;
1292
-
1293
- rowProportion = new Proportion ( ProportionType . Auto ) ;
1294
- _layout . RowsProportions . Add ( rowProportion ) ;
1295
- ++ y ;
1296
1309
}
1297
1310
}
1298
1311
0 commit comments