Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi every body; I used currencymanager to change position of selected row; it works well; but when I want change the row position to the new row; it doesn't work; just can change between first row to last row;
how can solve it?

C#
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;
using System.Data.SqlClient;

namespace GlassProducingManagement
{
    public partial class Customers : Form
    {
        SqlDataAdapter sqlda1;
        SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Hadi\documents\visual studio 2010\Projects\GlassProducingManagement\GlassProducingManagement\GMPdata.mdf;Integrated Security=True;User Instance=True");
        DataTable dtCustomers;
        CurrencyManager CM1;
        public Customers()
        {
            InitializeComponent();
            sqlda1 = new SqlDataAdapter("Select * From Customers", connection);            
            dtCustomers = new System.Data.DataTable();
            sqlda1.Fill(dtCustomers);
            dataGridView1.DataSource = dtCustomers;
            CM1 = (CurrencyManager)(this.BindingContext[dtCustomers]);

        private void btGotoNewRow_Click(object sender, EventArgs e)
        {            
            
            CM1.Position = CM1.Count;            
            dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
        }
    }
}


thank you very much for helping;

hadi
Posted
Comments
DamithSL 27-Apr-14 2:37am    
how you add row to dataGridView1?
Hadi IR 27-Apr-14 2:49am    
I want bind controls to fields of datagridview row; and locate a button to add new row by click it; So the user can insert inputs, and selected row in datagridview focus to new row (like access) and then by clicking other button, insert sqlcommand will execute.

1 solution

try below

C#
private void btGotoNewRow_Click(object sender, EventArgs e)
{
   CM1.AddNew();
   CM1.Position = CM1.Count; 
}
 
Share this answer
 
Comments
Hadi IR 27-Apr-14 3:03am    
thank you for the comment;
in this way one row will be added and the star row will be located below of that row
DamithSL 27-Apr-14 3:08am    
what is star row! i can't read you mind :)
Hadi IR 27-Apr-14 3:20am    
I mean the row below of last row that use for adding new row that has a star in the left side

I can't upload the image ;)
DamithSL 27-Apr-14 3:28am    
simple set DataGridView.AllowUserToAddRows property to false and use above button to add new row
Hadi IR 27-Apr-14 3:33am    
Yes; that row will be eliminated
thanks

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