Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView RowsAdded event not giving expected results

$
0
0

Hello,

Developing a C sharp Windows Forms program in VS 2013 Pro to consume a web service.

When I run this program:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LakesideConsumeServices.LakesideServiceReference;

namespace LakesideConsumeServices
{
    public partial class Form1 : Form
    {
        int rowCountInt = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void downloadCustomersButton_Click(object sender, EventArgs e)
        {
            NopServiceClient serviceClient = new NopServiceClient();
            string[] sqlStatements = new string[] { "Select Top 110 * From [Customer]" };
            dataGridView1.DataSource = serviceClient.ExecuteDataSet(sqlStatements, usernameOrEmailTextBox.Text, userPasswordTextBox.Text).Tables[0];

            recordCountTextbox.Text = rowCountInt.ToString();
            rowCountInt = 0;
        }

        private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {
            rowCountInt += 1;
        }
    }
}

recordCountTextbox.Text only shows a count of 4, while the grid displays 110 rows.

I used the debugger and it only hits the ExecuteDataSet line one time and the rowCountInt += 1 four times.

Why am I not getting a proper count of rows?

Any help would be gratefully appreciated.

Thanks,
Tony


Stop The World, I want To Get Off! ........... Life Isn't About Waiting For The Storm To Pass ... It's About Learning To Dance In The Rain.



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>