Click here to Skip to main content
Rate this: bad
good
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 19:00pm
Comments
ajitkadam at 3-Jan-13 1:10am
   
Is this is window application or Web application?
Harpreet_125 at 3-Jan-13 1:26am
   
it is windows application..
CHill60 at 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... Wink | ;)
There are many code-examples..
 

Have fun Wink | ;)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 489
1 ChintanShukla 295
2 Gihan Liyanage 250
3 Richard Deeming 250
4 RyanDev 250
0 Sergey Alexandrovich Kryukov 8,906
1 OriginalGriff 7,601
2 CPallini 2,603
3 Richard MacCutchan 2,121
4 Abhinav S 1,923


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2014
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