Click here to Skip to main content
15,303,034 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have to Form...
1) DataGrid View
2) Data Enter Form

now I wanna acces the Total no of Row in DataGridview...
on the 2nd form

my code is ...

( this code is on 2nd form )

public static RecordCount;
RecordCount = int.Parse(Client_Master_Grid.dgClientMaster.RowCount.ToString());

now problem is that...this will fetch data from the 1st form
but ans is still 0;

now what to do
plzz help me out..

how to write the rowcount code on 2nd form....[^][^]
Updated 26-Sep-12 6:13am
Rickin Kane 25-Sep-12 22:55pm
please elaborate , how r u navigating from one form to another , whats the purpose of showing the count and other details u think can help other understand what problem u r facing
Sergey Alexandrovich Kryukov 25-Sep-12 23:03pm
It's not nice to show the code which does not even compile. I mean, first line.
You need to copy and paste code from your project, or, even better, create a special code sample.

You need to stop wasting your time on UI development, urgently. You need to get some basic programming experience starting with most simple task, better be pure console application and master basic things, like variables, methods and parameter passing, static vs. instance, types and instances, and later "virtual", interfaces and other OOP.

Without that, what you try to do looks fantastic gibberish. The first line would not compile, because the type is not specified. The member should not be static and hardly can be public. Even if you need a public or internal member, it should rather be a property — public or internal field is a bad sign. And then, look what you are doing: get a string representation of some integer via ToString and then parse this string back to integer.

No questions can replace learning of the programming, especially if this is the very basics.

i hope datagridview source item as a datatable

int Cnt=0;
Bhimani Hiral 26-Sep-12 8:32am
not working...
Bhimani Hiral 26-Sep-12 8:32am
yes u r wirte that datagridview source iteam is as datatable
soo u r write but not work
vasim sajad 26-Sep-12 8:49am
can u post that code snippet ?
Bhimani Hiral 26-Sep-12 12:02pm
it's soo much long...
Bhimani Hiral 26-Sep-12 12:06pm
grid view form

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace OrderProcessAutomation
public partial class Client_Master_Grid : Form
#region Connection

SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString());


#region Initialization of DataTable & GridView

public static DataTable dtClientMaster;
public static DataGridView dgClientMaster;
public static int Gridcount;


public Client_Master_Grid()

private void panelTop_Paint(object sender, PaintEventArgs e)


private void Client_Master_Grid_Load(object sender, EventArgs e)
dgClientMaster = new DataGridView();
dtClientMaster = new DataTable();

dgClientMaster.Dock = DockStyle.Fill;
String load = "select ClientID,ClientName,Gender,Age,Address,State,City,Pincode,Phone,Mobile,EmailID,Remark from ClientMasterTbl";
//String cmb = "select * from CmbArea";
SqlDataAdapter adpt = new SqlDataAdapter(load,conn);

Client_Master_Grid.dgClientMaster.DataSource = Client_Master_Grid.dtClientMaster;
dgClientMaster.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgClientMaster.EditMode = DataGridViewEditMode.EditProgrammatically;
dgClientMaster.CellDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellDoubleClick);
dgClientMaster.RowHeadersVisible = false;
dgClientMaster.Columns["ClientID"].Visible = false;
dgClientMaster.AllowUserToAddRows = false;

dgClientMaster.RowTemplate.Height = 28;
dgClientMaster.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
//dgClientMaster.FirstDisplayedScrollingRowIndex = 10;


private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
Client_Master objm = new Client_Master();
Client_Master.FrmBackTrack = "ClientMasterGrid:";

Client_Master.ClientID = dgClientMaster.Rows[e.RowIndex].Cells["ClientID"].Value.ToString();
Client_Master.ClientName = dgClientMaster.Rows[e.RowIndex].Cells["ClientName"].Value.ToString();
Client_Master.Gender = dgClientMaster.Rows[e.RowIndex].Cells["Gender"].Value.ToString();
Client_Master.Age= dgClientMaster.Rows[e.RowIndex].Cells["Age"].Value.ToString();
Client_Master.Address= dgClientMaster.Rows[e.RowIndex].Cells["Address"].Value.ToString();
Client_Master.State= dgClientMaster.Rows[e.RowIndex].Cells["State"].Value.ToString();
Client_Master.City= dgClientMaster.Rows[e.RowIndex].Cells["City"].Value.ToString();
Client_Master.Pincode= dgClientMaster.Rows[e.RowIndex].Cells["Pincode"].Value.ToString();
Client_Master.Phone= dgClientMaster.Rows[e.RowIndex].Cells["Phone"].Value.ToString();
Client_Master.Mobile= dgClientMaster.Rows[e.RowIndex].Cells["Mobile"].Value.ToString();
Client_Master.EmailID= dgClientMaster.Rows[e.RowIndex].Cells["EmailID"].Value.ToString();
Client_Master.Remark = dgClientMaster.Rows[e.RowIndex].Cells["Remark"].Value.ToString();
Client_Master.Count = dgClientMaster.Rows[e.RowIndex].Index.ToString();

Gridcount = int.Parse(dgClientMaster.RowCount.ToString());


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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900