-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpdatagridviewcolumnadvanced.cs
1000 lines (960 loc) · 35.9 KB
/
rpdatagridviewcolumnadvanced.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Globalization;
using System.Threading;
namespace Reportman.Drawing.Forms
{
public enum ColumnDataType { Text, Integer, Numeric, Double, Date, DateTime, Time, ComboBox,ComboBoxList,Boolean,Password};
public enum TextBoxDataType { Text, Integer, Numeric, Double};
public class TextBoxAdvanced : TextBox
{
SortedList<char,char> validnumeric;
SortedList<char, char> validinteger;
SortedList<char, char> validdouble;
char decimalsep;
public TextBoxAdvanced()
: base()
{
FBarCodeBeginChar = '$';
FBarCodeEndChar = '%';
decimalsep = (char)0;
validnumeric = new SortedList<char, char>();
validdouble = new SortedList<char, char>();
string defsep = Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
validnumeric.Add('\n','\n');
validnumeric.Add('0', '0');
validnumeric.Add('1', '1');
validnumeric.Add('2','2');
validnumeric.Add('3','3');
validnumeric.Add('4','4');
validnumeric.Add('5','5');
validnumeric.Add('6','6');
validnumeric.Add('7','7');
validnumeric.Add('8','8');
validnumeric.Add('9','9');
validnumeric.Add('\b', '\b');
validnumeric.Add('-', '-');
validinteger = new SortedList<char, char>();
foreach (char c1 in validnumeric.Keys)
validinteger.Add(c1,c1);
foreach (char c in defsep)
{
if (decimalsep == (char)0)
decimalsep = c;
validnumeric.Add(c,c);
}
foreach (char c2 in validnumeric.Keys)
validdouble.Add(c2,c2);
validdouble.Add('e', 'e');
// Control-X
validdouble.Add((char)24, (char)24);
validnumeric.Add((char)24, (char)24);
validinteger.Add((char)24, (char)24);
// Control->Z
validdouble.Add((char)26, (char)26);
validnumeric.Add((char)26, (char)26);
validinteger.Add((char)26, (char)26);
// Control->C
validdouble.Add((char)3, (char)3);
validnumeric.Add((char)3, (char)3);
validinteger.Add((char)3, (char)3);
}
private TextBoxDataType FDataType;
public TextBoxDataType DataType
{
get { return FDataType; }
set
{
FDataType = value;
}
}
private bool FReadBarCode;
public bool ReadBarCode
{
get { return FReadBarCode; }
set
{
FReadBarCode = value;
}
}
private char FBarCodeBeginChar;
public char BarCodeBeginChar
{
get { return FBarCodeBeginChar; }
set
{
FBarCodeBeginChar = value;
}
}
protected override void OnTextChanged(EventArgs e)
{
if (FReadBarCode)
{
if (Text.Length>1)
{
if (Text[0] == FBarCodeBeginChar)
{
int index = 1;
while (index < Text.Length)
{
if (Text[index] == FBarCodeEndChar)
{
Text = Text.Substring(1, index - 1);
break;
}
index++;
}
}
}
}
base.OnTextChanged(e);
}
private char FBarCodeEndChar;
public char BarCodeEndChar
{
get { return FBarCodeEndChar; }
set
{
FBarCodeEndChar = value;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
switch (FDataType)
{
case TextBoxDataType.Numeric:
case TextBoxDataType.Double:
if (e.KeyCode == Keys.Decimal)
{
// No more than one comma admitted
string defsep = Thread.CurrentThread.CurrentUICulture.NumberFormat.NumberDecimalSeparator;
if (defsep.Length > 0)
{
if (defsep[0] != '.')
{
SendKeys.Send(defsep);
e.SuppressKeyPress = true;
}
}
}
break;
}
base.OnKeyDown(e);
}
protected override void OnKeyUp(KeyEventArgs e)
{
base.OnKeyUp(e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
int index;
switch (FDataType)
{
case TextBoxDataType.Numeric:
case TextBoxDataType.Double:
case TextBoxDataType.Integer:
if (e.KeyChar != (char)22)
{
SortedList<char, char> lvalidate;
if (FDataType == TextBoxDataType.Numeric)
lvalidate = validnumeric;
else
if (FDataType == TextBoxDataType.Double)
lvalidate = validdouble;
else
lvalidate = validinteger;
index = lvalidate.IndexOfKey(e.KeyChar);
if (index < 0)
e.KeyChar = (char)0;
// only 1 - symbol
if (e.KeyChar == '-')
{
// only at the beginning
if (SelectionStart <= 0)
{
index = Text.IndexOf('-');
if (index >= 0)
if (SelectionStart + SelectionLength < index)
e.KeyChar = (char)0;
}
else
e.KeyChar = (char)0;
}
// only 1 e symbol
if (e.KeyChar == 'e')
{
index = Text.IndexOf('-');
if (index >= 0)
e.KeyChar = (char)0;
}
// only 1 decimalsep symbol
if (decimalsep != (char)0)
{
if (e.KeyChar == decimalsep)
{
index = Text.IndexOf(decimalsep);
if (index >= 0)
e.KeyChar = (char)0;
}
}
}
break;
}
base.OnKeyPress(e);
}
}
public delegate bool DataColumnButtonClickEvent(DataGridViewColumn ncolumn,ref object value);
public class DataGridViewColumnAdvanced:DataGridViewColumn
{
private ColumnDataType FDataType;
private int FMaxInputLength;
private Image FImageButton;
public DataColumnButtonClickEvent ButtonClick;
public float ImageButtonScale = 1.0f;
public ColumnDataType DataType
{
get { return FDataType; }
set
{
FDataType = value;
}
}
public int MaxInputLength
{
get
{
return FMaxInputLength;
}
set
{
FMaxInputLength = value;
if (FMaxInputLength < 0)
FMaxInputLength = 0;
}
}
public static int ImageWidth
{
get
{
return Convert.ToInt32(20 * Reportman.Drawing.GraphicUtils.DPIScaleY);
}
}
public Image ImageButton
{
get { return FImageButton; }
set
{
FImageButton = value;
}
}
public DataGridViewColumnAdvanced()
: base(new DataGridViewCellAdvanced())
{
FDataType = ColumnDataType.Text;
}
public override int GetPreferredWidth(DataGridViewAutoSizeColumnMode autoSizeColumnMode, bool fixedHeight)
{
int nwidth = base.GetPreferredWidth(autoSizeColumnMode, fixedHeight);;
return nwidth;
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
base.CellTemplate = value;
}
}
}
public class DataGridViewCellAdvanced : DataGridViewTextBoxCell
{
//DataGridViewComboBoxEditingControl ComboBoxPicker;
// CheckBoxPickerControl CheckBoxPicker;
//DataGridViewTextBoxEditingControl TextBoxPicker;
//EllipsisEditingControl EllipsisPicker;
//ColorPickerControl ColorPickerc;
//NumericUpDownPickerControl NumericPicker;
//private EventHandler ButtonClicEvent;
//private EventHandler ClickFontStyleEvent;
public DataGridViewCellAdvanced()
: base()
{
//ButtonClicEvent = new EventHandler(ButtonClick);
}
private void ButtonClick(object sender, EventArgs args)
{
/* DataGridViewColumn col = GetColumn();
if (!(col is DataGridViewColumnAdvanced))
return;
DataGridViewColumnAdvanced ncolumn = (DataGridViewColumnAdvanced)GetColumn();
if (ncolumn.ButtonClick != null)
ncolumn.ButtonClick(ncolumn, new DataGridViewColumnEventArgs(ncolumn),);*/
}
private DataGridViewColumn GetColumn()
{
DataGridViewColumn ncol = null;
if (DataGridView != null)
{
ncol= DataGridView.Columns[ColumnIndex];
}
return ncol;
}
public override Type EditType
{
get
{
Type ntype = typeof(AdvancedEditingControl);
//Return the type of the editing contol that ComboBox uses.
/* if (DataGridView != null)
{
ObjectInspectorCellType celltype = (ObjectInspectorCellType)GetColumnValue("TYPEENUM");
switch (celltype)
{
case ObjectInspectorCellType.Decimal:
case ObjectInspectorCellType.Integer:
ntype = typeof(NumericUpDownPickerControl);
break;
case ObjectInspectorCellType.DropDownList:
ntype = typeof(DataGridViewComboBoxEditingControl);
break;
case ObjectInspectorCellType.Text:
case ObjectInspectorCellType.FontStyle:
ntype = typeof(DataGridViewTextBoxEditingControl);
break;
case ObjectInspectorCellType.Color:
ntype = typeof(ColorPickerControl);
break;
case ObjectInspectorCellType.Boolean:
ntype = typeof(CheckBoxPickerControl);
break;
case ObjectInspectorCellType.FontName:
ntype = typeof(EllipsisEditingControl);
break;
}
}*/
return ntype;
}
}
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
}
protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, System.ComponentModel.TypeConverter valueTypeConverter, System.ComponentModel.TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)
{
DataGridViewColumnAdvanced ncol = (DataGridViewColumnAdvanced)GetColumn();
if (ncol.DataType == ColumnDataType.Password)
{
if (value == null)
return "";
else
if (value == DBNull.Value)
return "";
else
if (value.ToString().Length == 0)
return "";
else
return "" + (char)0x25CF + (char)0x25CF + (char)0x25CF + (char)0x25CF + (char)0x25CF + (char)0x25CF;
}
else
return base.GetFormattedValue(value, rowIndex, ref cellStyle, valueTypeConverter, formattedValueTypeConverter, context);
}
}
public partial class AdvancedEditingControl : UserControl, IDataGridViewEditingControl
{
private TextBoxAdvanced textcontrol;
private DateTimePickerNullable datecontrol1;
//private DateTimePickerNullable datecontrol2;
private PictureBox picbo;
private ColumnDataType controldatatype;
private ColumnDataType FDataType;
private bool disabledchange;
private int FMaxInputLength;
public void DoKeyDown(object sender, KeyEventArgs args)
{
OnKeyDown(args);
}
public void DoKeyPress(object sender, KeyPressEventArgs args)
{
OnKeyPress(args);
}
public void DoKeyUp(object sender, KeyEventArgs args)
{
OnKeyUp(args);
}
public float ImageButtonScale = 1.0f;
public Image ImageButton
{
get { return picbo.Image; }
set
{
picbo.Image = value;
picbo.Visible = picbo.Image!= null;
picbo.SizeMode = PictureBoxSizeMode.Zoom;
picbo.Width = DataGridViewColumnAdvanced.ImageWidth;
CreateMainControl();
ResizeControls();
}
}
DataGridView m_dataGridView = null;
int m_rowIndex = 0;
bool m_valueChanged = false;
//string m_prevText = null;
public Control MainControl;
object prevvalue;
public new string Text
{
get
{
return textcontrol.Text;
}
set
{
textcontrol.Text = value;
}
}
public AdvancedEditingControl()
{
picbo = new PictureBox();
picbo.Click += new EventHandler(picboxButton_Click);
picbo.SizeMode = PictureBoxSizeMode.Zoom;
picbo.Width = DataGridViewColumnAdvanced.ImageWidth;
picbo.Dock = DockStyle.Right;
picbo.Visible = false;
Controls.Add(picbo);
}
private void mValueChange(object sender, EventArgs ev)
{
NotifyChange();
}
public void SaveCurrentValue()
{
NotifyChange();
}
void mLostFocus(object sender, EventArgs e)
{
NotifyChange();
}
void mDoubleClick(object sender, EventArgs e)
{
if (m_dataGridView is DataGridViewAdvanced)
{
DataGridViewAdvanced ngrid = ((DataGridViewAdvanced)m_dataGridView);
// aceptamos el valor
ngrid.FinishEdit();
ngrid.DoDoubleClick(MainControl);
}
}
private void SetValue(object newvalue)
{
CreateControl();
switch (FDataType)
{
case ColumnDataType.Double:
case ColumnDataType.Integer:
case ColumnDataType.Numeric:
textcontrol.Text = newvalue.ToString();
break;
case ColumnDataType.Text:
case ColumnDataType.Password:
textcontrol.Text = newvalue.ToString();
break;
case ColumnDataType.Date:
if (newvalue != DBNull.Value)
datecontrol1.Value = System.Convert.ToDateTime(newvalue).Date;
else
datecontrol1.Value = DateTime.MinValue;
break;
case ColumnDataType.Time:
if (newvalue != DBNull.Value)
datecontrol1.Value = System.Convert.ToDateTime(newvalue);
else
datecontrol1.Value = DateTime.MinValue;
break;
case ColumnDataType.DateTime:
if (newvalue != DBNull.Value)
datecontrol1.Value = System.Convert.ToDateTime(newvalue);
else
datecontrol1.Value = DateTime.MinValue;
break;
}
}
public object NewValue
{
get { return GetValue(); }
set
{
disabledchange = true;
try
{
SetValue(value);
}
finally
{
disabledchange = false;
}
NotifyChange();
}
}
private object GetValue()
{
object nresult = null;
switch (FDataType)
{
case ColumnDataType.Text:
case ColumnDataType.Password:
nresult = textcontrol.Text;
break;
case ColumnDataType.Integer:
case ColumnDataType.Double:
case ColumnDataType.Numeric:
nresult = textcontrol.Text;
break;
case ColumnDataType.Date:
case ColumnDataType.Time:
if (datecontrol1.Value == DateTime.MinValue)
nresult = DBNull.Value;
else
nresult = datecontrol1.Value.Date;
break;
case ColumnDataType.DateTime:
if (datecontrol1.Value == DateTime.MinValue)
nresult = DBNull.Value;
else
nresult = datecontrol1.Value;
break;
/* case ColumnDataType.DateTime:
if (datecontrol1.Value == DateTime.MinValue)
nresult = DBNull.Value;
else
nresult = datecontrol1.Value.Add(datecontrol2.Value - datecontrol2.Value.Date);
break;*/
}
return nresult;
}
private void SetNewValue(object nval)
{
switch (FDataType)
{
case ColumnDataType.Text:
case ColumnDataType.Password:
textcontrol.Text = nval.ToString();
break;
case ColumnDataType.Integer:
case ColumnDataType.Double:
case ColumnDataType.Numeric:
textcontrol.Text = nval.ToString();
break;
case ColumnDataType.Date:
case ColumnDataType.Time:
case ColumnDataType.DateTime:
if (nval.ToString() != "")
datecontrol1.Value = (DateTime)nval;
break;
/*case ColumnDataType.DateTime:
datecontrol1.Value = ((DateTime)nval).Date;
datecontrol2.Value = (DateTime)nval;
break;*/
}
}
private void picboxButton_Click(object sender, EventArgs e)
{
DataGridViewColumnAdvanced ncol = GetColumn();
if (ncol == null)
return;
if (ncol.ButtonClick != null)
{
object nvalue = GetValue();
bool aresult = ncol.ButtonClick(GetColumn(), ref nvalue);
if (aresult)
{
//SetValue(nvalue);
//NotifyChange();
}
}
}
private void NotifyChange()
{
if (disabledchange)
return;
if (!GetValue().Equals(prevvalue))
{
m_valueChanged = true;
m_dataGridView.NotifyCurrentCellDirty(true);
prevvalue = GetValue();
}
}
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
// Do nothing
}
public Cursor EditingControlCursor
{
get
{
return Cursors.IBeam;
}
}
public Cursor EditingPanelCursor
{
get
{
return Cursors.IBeam;
}
}
public DataGridView EditingControlDataGridView
{
get
{
return m_dataGridView;
}
set
{
m_dataGridView = value;
}
}
public object EditingControlFormattedValue
{
get
{
return GetEditingControlFormattedValue(DataGridViewDataErrorContexts.Display);
}
set
{
SetNewValue(value);
}
}
public int EditingControlRowIndex
{
get
{
return m_rowIndex;
}
set
{
m_rowIndex = value;
}
}
public bool EditingControlValueChanged
{
get
{
return m_valueChanged;
}
set
{
m_valueChanged = value;
}
}
public bool EditingControlWantsInputKey(Keys keyData, bool dataGridViewWantsInputKey)
{
if (FDataType == ColumnDataType.Date)
{
switch (keyData)
{
case Keys.Down:
return false;
case Keys.Up:
return false;
default:
return true;
}
}
switch (keyData)
{
case Keys.Tab:
return true;
case Keys.Home:
return true;
case Keys.End:
return true;
case Keys.Left:
if ((this.textcontrol.SelectionLength == 0)
&& (this.textcontrol.SelectionStart==0))
return false;
else
return true;
case Keys.Right:
if ((this.textcontrol.SelectionLength == 0)
&& (this.textcontrol.SelectionStart == this.textcontrol.Text.Length))
return false;
else
return true;
case Keys.Delete:
// this.textcontrol.Text = "";
return true;
case Keys.Enter:
NotifyChange();
return false;
case Keys.Up:
return false;
case Keys.Down:
return false;
default:
if (FDataType == ColumnDataType.Text)
return true;
else
return false;
}
}
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
object nvalue = GetValue();
if (nvalue == null)
return null;
string fvalue = "";
switch (FDataType)
{
case ColumnDataType.Text:
case ColumnDataType.Password:
fvalue = nvalue.ToString();
break;
case ColumnDataType.Double:
case ColumnDataType.Integer:
case ColumnDataType.Numeric:
fvalue = nvalue.ToString();
break;
case ColumnDataType.Date:
if (nvalue == DBNull.Value)
fvalue = "";
else
fvalue = ((DateTime)nvalue).ToString("dd/MM/yyyy");
break;
case ColumnDataType.Time:
if (nvalue == DBNull.Value)
fvalue = "";
else
fvalue = ((DateTime)nvalue).ToString("HH:mm:ss");
break;
case ColumnDataType.DateTime:
if (nvalue == DBNull.Value)
fvalue = "";
else
fvalue = ((DateTime)nvalue).ToString("dd/MM/yyyy HH:mm:ss");
break;
}
return fvalue;
}
public void CreateMainControl()
{
if (controldatatype != FDataType)
{
MainControl = null;
}
else
{
if (MainControl is TextBoxAdvanced)
{
if (((TextBoxAdvanced)MainControl).MaxLength != FMaxInputLength)
MainControl = null;
}
}
if (MainControl == null)
{
controldatatype = FDataType;
switch (FDataType)
{
case ColumnDataType.Text:
case ColumnDataType.Password:
case ColumnDataType.Numeric:
case ColumnDataType.Integer:
case ColumnDataType.Double:
if (textcontrol == null)
{
textcontrol = new TextBoxAdvanced();
textcontrol.BorderStyle = BorderStyle.None;
textcontrol.Font = this.EditingControlDataGridView.Font;
textcontrol.Multiline = true;
textcontrol.MinimumSize = new System.Drawing.Size(0,textcontrol.Height );
textcontrol.Multiline = false;
//textcontrol.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0);
textcontrol.LostFocus += new EventHandler(mLostFocus);
textcontrol.TextChanged += new EventHandler(mValueChange);
textcontrol.KeyDown += new KeyEventHandler(DoKeyDown);
textcontrol.KeyUp += new KeyEventHandler(DoKeyDown);
textcontrol.KeyPress += new KeyPressEventHandler(DoKeyPress);
textcontrol.DoubleClick += new EventHandler(mDoubleClick);
MainControl = textcontrol;
textcontrol.DataType = (TextBoxDataType)FDataType;
textcontrol.MaxLength = FMaxInputLength;
if (FDataType == ColumnDataType.Password)
textcontrol.UseSystemPasswordChar = true;
else
textcontrol.UseSystemPasswordChar = false;
Controls.Add(textcontrol);
}
else
{
textcontrol.Visible = true;
textcontrol.DataType = (TextBoxDataType)FDataType;
textcontrol.MaxLength = FMaxInputLength;
if (FDataType == ColumnDataType.Password)
textcontrol.UseSystemPasswordChar = true;
else
textcontrol.UseSystemPasswordChar = false;
MainControl = textcontrol;
}
ResizeControls();
break;
case ColumnDataType.Date:
case ColumnDataType.Time:
case ColumnDataType.DateTime:
if (datecontrol1 == null)
{
datecontrol1 = new DateTimePickerNullable();
datecontrol1.ValueChanged += new EventHandler(datecontrol1_ValueChanged);
//datecontrol2 = new DateTimePickerNullable();
//datecontrol2.ValueChanged += new EventHandler(datecontrol1_ValueChanged);
datecontrol1.Format = DateTimePickerFormat.Custom;
if (FDataType == ColumnDataType.DateTime)
datecontrol1.CustomFormat = "dd/MM/yyyy HH:mm:ss";
else
if (FDataType == ColumnDataType.Time)
datecontrol1.CustomFormat = "HH:mm:ss";
else
if (FDataType == ColumnDataType.Date)
datecontrol1.CustomFormat = "dd/MM/yyyy";
//datecontrol2.Format = DateTimePickerFormat.Custom;
//datecontrol2.CustomFormat = "hh:mm:ss";
//datecontrol2.KeyDown += new KeyEventHandler(DoKeyDown);
//datecontrol2.KeyUp += new KeyEventHandler(DoKeyDown);
//datecontrol2.KeyPress += new KeyPressEventHandler(DoKeyPress);
datecontrol1.KeyDown += new KeyEventHandler(DoKeyDown);
datecontrol1.KeyUp += new KeyEventHandler(DoKeyDown);
datecontrol1.KeyPress += new KeyPressEventHandler(DoKeyPress);
datecontrol1.LostFocus += new EventHandler(mLostFocus);
datecontrol1.ValueChanged += new EventHandler(mValueChange);
//datecontrol2.LostFocus += new EventHandler(mLostFocus);
//datecontrol2.ValueChanged += new EventHandler(mValueChange);
datecontrol1.DoubleClick += new EventHandler(mDoubleClick);
//datecontrol2.DoubleClick += new EventHandler(mDoubleClick);
Controls.Add(datecontrol1);
//Controls.Add(datecontrol2);
}
//datecontrol1.Visible = ((FDataType == ColumnDataType.Date) || (FDataType == ColumnDataType.DateTime));
//datecontrol2.Visible = ((FDataType == ColumnDataType.Time) || (FDataType == ColumnDataType.DateTime));
/*if (FDataType == ColumnDataType.Time)
MainControl = datecontrol2;
else
MainControl = datecontrol1;*/
MainControl = datecontrol1;
MainControl.Visible = true;
ResizeControls();
break;
}
}
else
{
}
}
void datecontrol1_ValueChanged(object sender, EventArgs e)
{
m_dataGridView.NotifyCurrentCellDirty(true);
}
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, height, specified);
CreateMainControl();
ResizeControls();
}
private void ResizeControls()
{
MainControl.Top = (this.Height - MainControl.Height) / 2;
int offset=0;
if (picbo.Visible)
offset=picbo.Width;
//if (FDataType == ColumnDataType.DateTime)
//{
// datecontrol1.Width = (this.Width - offset) / 2;
//datecontrol2.Width = datecontrol1.Width;
//datecontrol2.Left = datecontrol1.Width;
//datecontrol2.Top = datecontrol1.Top;
//}
//else
{
MainControl.Width = this.Width - offset;
}
}
private DataGridViewColumnAdvanced GetColumn()
{
DataGridViewColumnAdvanced nresult = null;
if (m_dataGridView == null)
return nresult;
if (m_dataGridView.CurrentCell == null)
return nresult;
if (m_dataGridView.CurrentCell.ColumnIndex < 0)
return nresult;
return (DataGridViewColumnAdvanced)m_dataGridView.Columns[m_dataGridView.CurrentCell.ColumnIndex];
}
public void PrepareEditingControlForEdit(bool selectAll)
{
DataGridViewColumnAdvanced ncol = GetColumn();
if (FDataType != ncol.DataType)
{
FDataType = ncol.DataType;
if (MainControl!=null)
{
MainControl.Visible=false;
MainControl = null;
}
}
FMaxInputLength = ncol.MaxInputLength;
CreateMainControl();
disabledchange = true;
try
{
prevvalue = DBNull.Value;
if (this.m_dataGridView.CurrentCell.Value != null)
prevvalue = this.m_dataGridView.CurrentCell.Value;
SetValue(prevvalue);
prevvalue = GetValue();
}
finally
{
disabledchange = false;
}
if (this.textcontrol!=null)
if (selectAll)
this.textcontrol.SelectAll();
if (MainControl != null)
if (MainControl.Visible)
MainControl.Focus();
ImageButtonScale = ncol.ImageButtonScale;
ImageButton = ncol.ImageButton;
}
public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}
public override bool Focused
{
get
{
if (MainControl != null)
return MainControl.Focused;
else
return base.Focused;
}
}
protected override void Dispose(bool disposing)
{
if (textcontrol!=null)
textcontrol.Dispose();
if (datecontrol1!=null)
datecontrol1.Dispose();
// if (datecontrol2!=null)
// datecontrol2.Dispose();
if (picbo!=null)
picbo.Dispose();
base.Dispose(disposing);
}
}
}