Public
Property
Qty
As
Integer
Public
Property
expdate
As
Date
Public
Property
Dis
As
Integer
Public
Property
DType
As
JomlaItem.JType
Public
Property
Client
As
Client
Public
Overrides
Function
ToString()
As
String
Return
Qty.ToString &
"
| "
& expdate.ToString(
"
dd/MM/yyyy"
)
End
Function
End
Class
Private
Sub
TextBoxSales_TextChanged(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
Dim
qtties
As
New
List(
Of
QtyObject)
Dim
b = From r
As
DataRow
In
ds.tblItems.Rows
Where r.Item(
1
).ToString = str
Select
price =
CDbl
(r.Item(
2
)), code =
CInt
(r.Item(
0
))
If
b.Count >
0
Then
dgvSales.CurrentRow.Cells(
1
).Value = b(
0
).price
x = b(
0
).code
Dim
d = From r
As
DataRow
In
ds.tblEXPData.Rows
Where
CInt
(r.Item(
1
)) = x
Select
quantity =
CInt
(r.Item(
2
)), expdate =
CDate
(r.Item(
3
))
Order By expdate
If
d.Count >
0
Then
For
i =
0
To
d.Count -
1
Dim
q
As
New
QtyObject
q.Qty = d(i).quantity
q.expdate = d(i).expdate
qtties.Add(q)
With
DirectCast
(dgvSales.CurrentRow.Cells(
2
), DataGridViewComboBoxCell)
.DataSource = qtties
End
With
DirectCast
(dgvSales.CurrentRow.Cells(
2
), DataGridViewComboBoxCell).DataSource =
Nothing
End
If
End
If
Catch
ex
As
Exception
End
Try
End
Sub
i asked the question this way because i searched google and the similar problems were answered that the problem is in setting the displaymember and the valuemember,
the combobox cell is populated with data without problems, the exception is thrown when it loses focus the exact exception message is : The following exception occurred in the datagridview : System.argumentException :datagridviewcomboboxcell value is not valid To replace this default dialog please handle the dataerror event.
if the problem that caues the error message (datagridviewcomboboxcell value invalid exception) is elsewhere ,please kindly help me solving it,
Thanks alot.
Not sure if it's your problem (you could've been more specific, like what's the
Exception
[
^
] message and where is it thrown...), but setting a
DataSource
[
^
] to
Nothing
usually doesn't work.
Imagine this, when binding takes place a data bound object looks in the objects in its
DataSource Property
to find the values of the
ValueMember
[
^
] and
DisplayMember
[
^
] Properties. It does this using
Reflection
[
^
]. Now when you tell your data bound object that its
DataSource
is
Nothing
it will check for the
ValueMember
and
DisplayMember
on
Nothing
. That is just silly because
Nothing
doesn't have any members at all! In fact,
Nothing
is just that, nothing.
So instead of doing the following:
DirectCast
(dgvSales.CurrentRow.Cells(
2
), DataGridViewComboBoxCell).DataSource =
Nothing
Try this:
DirectCast
(dgvSales.CurrentRow.Cells(
2
), DataGridViewComboBoxCell).DataSource =
New
List(
Of
QtyObject)Hope it helps :)
With
DirectCast
(dgvSales.CurrentRow.Cells(
2
), DataGridViewComboBoxCell)
.DataSource = qtties
.displaymember=
"
expdate"
.valuemember=
"
quantity"
End
With
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
i tried your solution though, but i still get the exception,
look,the combobox cell is populated with data with no problems,
the exception is thrown when it loses focus
the exact exception message is :
the following exception occured in the datagridview:
system.argumentexception :datagridviewcomboboxcell value is not valid.
To replace this default dialog please handle the dataerror event.