[VB.NET] DataGrid besoin d'aide pour un ComboBoxColumn
Bonjour,
J'aurai besoin de vos lumières de pro sur lanterne de débutant :)
Mon but : Afficher une combobox dans un datagrid
pour ce faire j'utilise la classe datagridComboBoxColumn.
Je suis ce qu'il demande et je réalise cela (partie du source) :
Code:
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
|
Dim dt As DataTable = New DataTable("tyear")
Dim dc As DataColumn
dc = New DataColumn
dc.ColumnName = "yearid"
dc.DataType = System.Type.GetType("System.Int32")
dc.Unique = True
dc.ReadOnly = True
dt.Columns.Add(dc)
dc = New DataColumn
dc.ColumnName = "yearvalue"
dc.DataType = System.Type.GetType("System.Int32")
dc.Unique = False
dc.ReadOnly = False
dt.Columns.Add(dc)
Dim pkcol(0) As DataColumn
pkcol(0) = dt.Columns("yearid")
dt.PrimaryKey = pkcol
Dim i As Integer
Dim dr As DataRow
For i = 1 To i = 11
dr = dt.NewRow
dr(0) = i
dr(1) = 2000 + i
dt.Rows.Add(dr)
Next i
Dim colStyle3 As DataGridComboBoxColumn2 = New DataGridComboBoxColumn2(dt)
With colStyle3
.MappingName = "year"
.HeaderText = "Y.e"
.Width = 60
.NullText = String.Empty
End With |
J'essaye de dérouler le combo j'obtient comme message :
System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values.
Parameter name: '0' is not a valid value for 'index'.
at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
at DgTs.DataGridComboBoxColumn2.Edit(CurrencyManager source, Int32 rowNum, Rectangle Bounds, Boolean readOnly, String instant Text, Boolean cellIsVisible) in H:\Projects\Apps\DgTs\DataGridComboBox2.vb:line57
edit: En vérifiant j'ai la valeur selectedindex de ma combo qui est à -1.
Merci d'avance de vos lumière :)
Amicalement,
Looney