Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:04:34+00:00 2026-05-23T12:04:34+00:00

Basically I have a datagridview which I retrieve from database and 3 of the

  • 0

Basically I have a datagridview which I retrieve from database and 3 of the database field column I combine into a column in datagridview.

But now the problem come, I need to do update but before that I need to validate what the user have editing before click on the update button, but I don’t know how to validate them when they are in the same column in the datagridview.

I am able to validate a column with only one database field

p.s I am doing editing and updating in the datagridview, I need to validate that 3 database field column.

This is how I call my databasase into the datagridview

ps. the position is int

protected void BindStaff()
{
  SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=BRandCom;Integrated Security=True");
  SqlDataAdapter adapter = new SqlDataAdapter("SELECT StaffID, (StaffName+','+ StaffNRIC+','+ Position + ';')as StaffDetail, yearIn, age, address, email, stayIndicator FROM StaffBook", conn);
  DataSet ds = new DataSet();
  adapter.Fill(ds);
  DGVStaffBook.DataSource = ds.Tables[0];
}

this is the column i am saying i am able to validate (only one database field column)

private void DGVStaffBook_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
      if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
      {

        int stayInd;

       if (e.ColumnIndex == 6)
        {
          stayInd = Convert.ToInt32(DGVStaffBook.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);

          if (stayInd != 0 && stayInd != 1)
          {
            MessageBox.Show("Please enter only 1 or 0");
            DGVStaffBook.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = DBNull.Value;
          }
          else
            return;

        }
      }

    }

i try this for position , but it give me error: input string was not correct format

  private void DGVStaffBook_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
            {

                             if (e.ColumnIndex == 1)
                {
                    String[] position = null;
                    position = Convert.ToString(DGVStaffBook.CurrentRow.Cells[1].Value).Split(',');

                    if (int.Parse(position[2]) != 1 && int.Parse(position[2])!=2 ) 
                    {
                        MessageBox.Show("Please Update number type accordingly:" + Environment.NewLine + "1  - High rank only " + Environment.NewLine + "2  -Low Rank" );
                    }
                    else 
                        return;

                }
            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:04:34+00:00Added an answer on May 23, 2026 at 12:04 pm

    IMO displaying 3 database fields and allowing the user to edit the same in one column is dangerous. Suggest you to show them as 3 separate columns instead.

    Maybe you can also try by making the 3 corresponding properties and merge them via a separator like | which would not occur in your fields via a fourth property. Now when you get the value split the same on | and perform your checks and also assign back those respective values to the 3 corresponding properties. (But i wouldn’t recommend this)
    Field1 Field2 Field3

    StaffDetails — Field1+”|” +Field2+”|” + Field3

    Then use e.FormattedValue.ToString() and split this on |to get string[] of 3 ,now validate

    Also you can take a look on creating a Column of MaskedTextBox this will also help but the User experience is gonna be pathetic

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView with cells from a database file that contains data. Basically,
First post, but long time browser :) So here's my problem: Basically I have
I have a DataGridView that displays data from a MS Access database. I'm using
Say I have a DataGridView in which I dynamically build up a ComboBox column
I'm simply trying to delete a row from a DataGridView. Basically, the first column
I basically have an application that has, say 5 threads, which each read from
I have a nice DataGridView showing what is basically some kind of log data
I basically have a page which shows a processing screen which has been flushed
I basically have the exact same problem as here: http://stackoverflow.com/questions/2416155/issue-in-executing-spring-web-project-in-eclipse-on-tomcat-server but the fix for
I currently have a functioning in-house Windows Forms application which extensively uses the DataGridView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.