Click here to Skip to main content
15,907,396 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one datagridview control and one submit button in my form. i have taken four columns in datagridview. what i want is, on click of the submit button first it will check, is there any null or empty column in grid view. if so, then it will show message box "Enter the value" otherwise all the records should be saved in database.
And one more thing records should be saved only a single time if the code is running in the loop.. i will be very thankful of yours if you give me solution..
Posted
Updated 13-Mar-20 6:49am
Comments
ajitkadam 3-Jan-13 1:10am    
Is this is window application or Web application?
Harpreet_125 3-Jan-13 1:26am    
it is windows application..
CHill60 7-Jan-13 7:17am    
Have you actually attempted to do this yourself? If so then use the Improve Question widget to post the code and explain what problems you are experiencing.
If not then have a go at it yourself first - this sounds like homework and you will never learn unless you try.

1 solution

it sounds like homework but i will help you a little bit...

VB
For row As Integer = 0 To DataGridView1.Rows.Count - 1
    For column As Integer = 0 To DataGridView1.Columns.Count

        If IsDBNull(DataGridView1.Rows(row).Cells(column).Value) Or String.IsNullOrEmpty(DataGridView1.Rows(row).Cells(column).Value) Then
            'TO DO.... open a WinForm as Dialog
        End If

    Next
Next


With this code you can check each cell.
Design a new WinForm, with a textbox ....
define: public newValue as string = ""
add the ok button click eventhandler -> newValue = textbox1.text...
and at the last line Me.DialogResult = Windows.Forms.DialogResult.OK

at the ToDo section you have to add a litte bit code:
VB
dim nForm as new XXXXX
if nForm.ShowDialog() = Windows.Forms.DialogResult.OK Then
datagridview1.rows(row).cells(column).value = nForm.newValue
End IF



And then you can write the datagridview back to the database.. Use google... ;)
There are many code-examples..


Have fun ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900