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 6714695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:32+00:00 2026-05-26T08:31:32+00:00

The following code is used to populate a DGV: private void frmSwitch_Load(object sender, EventArgs

  • 0

The following code is used to populate a DGV:

  private void frmSwitch_Load(object sender, EventArgs e)
    {
         // TODO: This line of code loads data into the 'newCityCollectionDataSet.PropertyInformation' table. You can move, or remove it, as needed.
        this.propertyInformationTableAdapter.Fill(this.newCityCollectionDataSet.PropertyInformation);
        // TODO: This line of code loads data into the 'newCityCollectionDataSet.ClientTable' table. You can move, or remove it, as needed.
        this.clientTableTableAdapter.Fill(this.newCityCollectionDataSet.ClientTable);

    }

This code allows me to pass the necessary information to the “summary form”:

    private void propertyInformationDataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        System.Data.DataRowView SelectedRowView;
        newCityCollectionDataSet.PropertyInformationRow SelectedRow;

        SelectedRowView = (System.Data.DataRowView)propertyInformationBindingSource.Current;
        SelectedRow = (newCityCollectionDataSet.PropertyInformationRow)SelectedRowView.Row;

        frmSummary SummaryForm = new frmSummary(this);
        SummaryForm.LoadCaseNumberKey(SelectedRow.CaseNumberKey, true, null);
        SummaryForm.LoadBRTNumberKey(SelectedRow.BRTNumber, null);
        SummaryForm.Show();

    }

What I am looking to do is pass the SelectedRow and add 1 to go to the next row if the current SelectedRow is no longer valid (for instance when FileFinishedCheckBox is checked on the “summary form”). I also want the same thing to happen anytime a checkbox is checked on the DataGridview so people do not have to scroll back to the file they are working on.

The code that performs the refresh whenever needed is as follows:

        public void PerformRefresh() 
        {
         this.propertyInformationBindingSource.EndEdit();
         this.propertyInformationTableAdapter.Fill(this.newCityCollectionDataSet.PropertyInformation);
         this.propertyInformationDataGridView.Refresh();      
        }

Any help would be great.

  • 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-26T08:31:33+00:00Added an answer on May 26, 2026 at 8:31 am

    This question seems to be in two parts:

    1. How to communicate between two windows forms
    2. How to change the selected row in a datagridview

    There are many different ways of achieving both tasks so I’m just going to give you two that will work. The first (for windows forms) is the simplest, while the second (for changing the selected row) is in my opinion the correct method.

    Communication between windows forms

    The most straightforward way to communicate between two windows forms is pass a reference to one form into the other form.

    So say you have Form1 which opens Form2, you could do something like this:

    public partial class Form1 : Form
    {
    
        public Form1()
        {
            InitializeComponent();
            Form2 f = new Form2(this);
            f.Show();
        }
    
        public void ShowMessage(string message)
        {
            MessageBox.Show(message);
        }        
    }
    
    public partial class Form2 : Form
    {
        private Form1 _parentForm;
    
        public Form2(Form1 parentForm)
        {
            InitializeComponent();
            _parentForm = parentForm;
    
            _parentForm.ShowMessage("I am a message from form1);
        }   
    }
    

    So in your example you would add a method to the parent form which takes as its parameter the unique value for the row selected in dgv3 to show in gdv1. In the method (which is a member of the parentForm you put the centering code which I will show below).

    Other ways of doing this include passing a delegate to the child form which is the method to center the datagridview. This has the advantage that you are no longer tied down to always passing in Form1 and can even provide different actions in resonse to the checkbox but is slightly more complicated to implement.

    Centering on a selected record in a DataGridView

    My preferred way of doing this is to use a bindingsource to provide the datasource for the grid. You can also directly access the grid position using the CurrentCell property but with the bindingsource you get a bit more bang for your buck.

    In the code below we have a form which creates a BindingSource, sets its datasource to a BindingList of type MyBindingList and then sets the binding source as the datasource of a datagridview.

    The objects within the BindingList have a unique property “PrimaryKey” allowing us to find them.

    Then I show the centering code which is actually very simple.

    First we get the index in the binding source of the desired you by calling the Find() method of the binding source.

    Second we change the binding sources position (this also updates the datagridview display).

    Finally we change the FirstDisplayedScrollingRowIndex of the datagridview so that the selected row is not at the very top or bottom of the grid (you will want to add a check to ensure this is a valid index if you use this line).

    public partial class Form1 : Form
    {
        BindingSource bs;
    
        public Form1()
        {
            InitializeComponent();
    
    
            bs = new BindingSource();
    
            MyBindingList<BackingObject> backing_objects = new MyBindingList<BackingObject>();
            backing_objects.Add(new BackingObject{ PrimaryKey = 1, Name  = "Fred", Hidden = "Fred 1"});
    
            bs.DataSource = backing_objects;
    
            dataGridView1.DataSource = bs;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            int index = bs.Find("PrimaryKey", 5);
            bs.Position = index;
            dataGridView1.FirstDisplayedScrollingRowIndex = index - 1;            
        }
    }
    

    Now the last this to note is that bindinglist out of the box does not support the Find() method of the bindingsource. This is why I use my custom MyBindingList. Code to implement this can be found here.

    Essentially you need a class like the following:

    public class MyBindingList<T> : BindingList<T>
    {
        protected override bool SupportsSearchingCore
        {
            get
            {
                return true;
            }
        }
    
        protected override int FindCore(PropertyDescriptor prop, object key)
        {
            // Get the property info for the specified property. 
            PropertyInfo propInfo = typeof(T).GetProperty(prop.Name);
            T item;
    
            if (key != null)
            {
                // Loop through the items to see if the key 
                // value matches the property value. 
                for (int i = 0; i < Count; ++i)
                {
                    item = (T)Items[i];
                    if (propInfo.GetValue(item, null).Equals(key))
                        return i;
                }
            }
            return -1;
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following c# code in a web form: protected void GridView1_SelectedIndexChanged(object sender,
I've got the following code: void ReferenceManager_DoWork(object sender, DoWorkEventArgs e) { try { //
I have the following function: public void rpSearchResults_ItemDataBound(Object Sender, RepeaterItemEventArgs e) { if (e.Item.ItemType
I swear the following code used to work, even in IE7 but now i
here the following code is used to view the present modal view controller. [[self
i have used following code to repeat a process creation/close iteratively dim vProcessInfo as
I have used following code to create a simple PDF file. It executes fine
The following code is being used to disable a Submit button once it has
I used following code, but it displays only 2 digit of ISO country name.
I have the following code - it is used to load a drop down

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.