none
How to show message for Empty RRS feed

  • Question

  • I want to show a message in If DataGridView cell(6) = Empty then Show MsgBox"Enter a Value". How to show this Message. I write some code for Empty and Out of Stock. But Empty Code is not working show error message this :

    I Write this code below :

    Private Sub DGV_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DGV.CellValidating Dim dgv As DataGridView = CType(sender, DataGridView) For r As Integer = 0 To dgv.RowCount - 1 For c As Integer = 0 To dgv.ColumnCount - 1 If dgv.Rows(r).Cells(6).Value Is Nothing Then MsgBox("Cell is empty") Else Cons() Str = "(Select Qty from tbl_mstock where batch_no = '" & dgv.CurrentRow.Cells(3).Value & "')" Cmd = New MySqlCommand(Str, Con) Dr = Cmd.ExecuteReader While Dr.Read = True If dgv.Columns(e.ColumnIndex).Name = "Item_Qty" AndAlso e.FormattedValue > Dr(0) Then e.Cancel = True MessageBox.Show("Out of Stock") End If End While connection_close() End If Next Next Get_Value() End Sub

    Please help my problem.


    dopenoinam

    Tuesday, June 20, 2017 7:11 AM

All replies

  • I want to show a message in If DataGridView cell(6) = Empty then Show MsgBox"Enter a Value".

    You have not indicated the line where the error occurs. When the program stops with the error, examine each variable in that line.  One of them will be an empty string.  That is the variable that you are trying to convert to a number (double), which is invalid for an empty string.   You probably need to test it for "" before attempting to convert it to a number.  There is no code for 'Show MsgBox "Enter a Value"' so it is difficult to guess where this is happening.

    Tuesday, June 20, 2017 8:27 AM
  • Hi Dopen,

    Please replace the dgv.Rows(r).Cells(6).Value Is Nothing with String.IsNullOrEmpty(dgv.Rows(r).Cells(6).Value.ToString()), and try again.

    Best Regards,
    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.





    Tuesday, June 20, 2017 8:34 AM
    Moderator
  • I have error in this line

    If dgv.Columns(e.ColumnIndex).Name = "Item_Qty" AndAlso e.FormattedValue > Dr(0) Then


    dopenoinam

    Tuesday, June 20, 2017 8:54 AM
  • We can help you to overcome this error.

    And then 10 minutes later you get an error on an other place. 

    Why don't you not simply use a TableAdapter to overcome this kind of problems, it is almost a pair with the DataGridView while you use a kind of vintage MSFlexgrid programming combined with even older vintage DAO style. 


    Success
    Cor


    Tuesday, June 20, 2017 8:54 AM
  • I have error in this line

    When the error occurred, and you examined the variables used in that line (dgv.Columns(e.ColumnIndex).Name, FormattedValue and DR(0)) was one of them an empty string?  That's the one that the compiler is trying to convert to a number, and of course it can't because an empty string is not a number so it throws the error you are seeing.

    Tuesday, June 20, 2017 9:45 AM
  • I was datagridview insert data from another Form then focus to this cell, But Press Enter Key or Tab Key this cell is Empty then Show Message "Cell is Empty".  

    dopenoinam

    Tuesday, June 20, 2017 9:55 AM
  • Hi Dopen,

    I agree with Acamar's opinion, e.FormattedValue or Dr(0) was one of them an empty string. you can add breakpoint to the place where you get this error, and print e.FormattedValue and Dr(0), if these value are empty, You may want to add conditions to prevent this from happening

    Best Regards,

    Cherry.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 21, 2017 1:48 AM
    Moderator