Click here to Skip to main content
12,635,662 members (26,650 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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 2-Jan-13 20:00pm
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

        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:
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 ;)
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100