Click here to Skip to main content
15,916,188 members
Home / Discussions / C#
   

C#

 
GeneralRe: Query takes a long time and then crashes............??? Pin
Reality Strikes9-Dec-08 8:54
Reality Strikes9-Dec-08 8:54 
GeneralRe: Query takes a long time and then crashes............??? Pin
leppie9-Dec-08 20:23
leppie9-Dec-08 20:23 
GeneralRe: Query takes a long time and then crashes............??? Pin
Ashfield10-Dec-08 1:15
Ashfield10-Dec-08 1:15 
GeneralRe: Query takes a long time and then crashes............??? Pin
Reality Strikes10-Dec-08 3:44
Reality Strikes10-Dec-08 3:44 
QuestionCSEXWB - Managing Security Pin
Saul Johnson9-Dec-08 5:58
Saul Johnson9-Dec-08 5:58 
QuestionInserting row in DataGridView doesn't update Primary Key Pin
dj_jeff9-Dec-08 5:32
dj_jeff9-Dec-08 5:32 
AnswerRe: Inserting row in DataGridView doesn't update Primary Key Pin
led mike9-Dec-08 5:46
led mike9-Dec-08 5:46 
GeneralRe: Inserting row in DataGridView doesn't update Primary Key Pin
dj_jeff9-Dec-08 20:41
dj_jeff9-Dec-08 20:41 
led mike wrote:
Microsoft cleverly hides that information in the documentation[^]


I don't really know where I should handle this. Everything is controlled by the BindingNavigator and BindingSource. The document samples refer to a manual insert and console display.

Here's my current code of that Test form.
I guess Insert handling in RowsAdded- Event wouldn't be good because of running this event on building the datagridview.

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

namespace DummyProject
{
	public partial class frmTest : Form
	{
		SqlDataAdapter dataAdapter;
		DataTable table;
		SqlCommandBuilder commandBuilder;
		
		public frmTest()
		{
			InitializeComponent();
		}

		private void updateGridView()
		{
			this.Validate();
			tblLangBindingSource.EndEdit();
			dataAdapter.Update(table);
		}
		
		private void frmTest_Load(object sender, EventArgs e)
		{
			string strCon = "Data Source=MyServer;Initial Catalog=MyDB;User ID=MyUser;Password=MyPass;";
			string strSQL = "select LangId AS ID, LangName AS Name FROM tbl_Lang";
			dataAdapter = new SqlDataAdapter(strSQL, strCon);
			commandBuilder = new SqlCommandBuilder(dataAdapter);

			// Populate a new data table and bind it to the BindingSource.
			table = new DataTable();
			table.Locale = System.Globalization.CultureInfo.InvariantCulture;
			dataAdapter.Fill(table);
			tblLangBindingSource.DataSource = table;

			// Resize the DataGridView columns to fit the newly loaded content.
			dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);

			// you can make it grid readonly.
			//dataGridView1.ReadOnly = true;  

			// finally bind the data to the grid
			dataGridView1.DataSource = tblLangBindingSource;
			bindingNavigator1.BindingSource = tblLangBindingSource;
		}

		private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			this.updateGridView();
		}

		private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
		{
			this.updateGridView();
		}

		private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
		{
			this.updateGridView();
		}

		private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
		{
			foreach(DataGridViewRow dgvr in dataGridView1.SelectedRows)
			{
				dataGridView1.Rows.RemoveAt(dgvr.Index);
			}

			this.updateGridView();
		}
	}
}

GeneralRe: Inserting row in DataGridView doesn't update Primary Key Pin
led mike10-Dec-08 5:28
led mike10-Dec-08 5:28 
GeneralRe: Inserting row in DataGridView doesn't update Primary Key Pin
dj_jeff11-Dec-08 6:13
dj_jeff11-Dec-08 6:13 
GeneralRe: Inserting row in DataGridView doesn't update Primary Key Pin
led mike11-Dec-08 6:50
led mike11-Dec-08 6:50 
Questionshould client machine contain sqlserver installed , if i am using sqlserver as backend Pin
praveenvkumarv9-Dec-08 3:46
praveenvkumarv9-Dec-08 3:46 
AnswerRe: should client machine contain sqlserver installed , if i am using sqlserver as backend Pin
Abhijit Jana9-Dec-08 4:12
professionalAbhijit Jana9-Dec-08 4:12 
GeneralRe: should client machine contain sqlserver installed , if i am using sqlserver as backend Pin
praveenvkumarv9-Dec-08 4:21
praveenvkumarv9-Dec-08 4:21 
AnswerRe: should client machine contain sqlserver installed , if i am using sqlserver as backend Pin
Lev Danielyan9-Dec-08 4:39
Lev Danielyan9-Dec-08 4:39 
Questiondeployment using sqlserver and c# Pin
praveenvkumarv9-Dec-08 3:43
praveenvkumarv9-Dec-08 3:43 
AnswerRe: deployment using sqlserver and c# Pin
Abhijit Jana9-Dec-08 4:17
professionalAbhijit Jana9-Dec-08 4:17 
AnswerRe: deployment using sqlserver and c# Pin
Lev Danielyan9-Dec-08 4:34
Lev Danielyan9-Dec-08 4:34 
QuestionEvent Log Permissions Pin
prod@pt9-Dec-08 3:24
prod@pt9-Dec-08 3:24 
AnswerRe: Event Log Permissions Pin
Brij9-Dec-08 3:38
mentorBrij9-Dec-08 3:38 
GeneralRe: Event Log Permissions Pin
Abhijit Jana9-Dec-08 4:15
professionalAbhijit Jana9-Dec-08 4:15 
Questionthe way to save a image from picturebox Pin
thucbv9-Dec-08 2:14
thucbv9-Dec-08 2:14 
AnswerRe: the way to save a image from picturebox Pin
SeMartens9-Dec-08 2:40
SeMartens9-Dec-08 2:40 
AnswerRe: the way to save a image from picturebox Pin
Brij9-Dec-08 2:43
mentorBrij9-Dec-08 2:43 
GeneralRe: the way to save a image from picturebox Pin
Luc Pattyn9-Dec-08 2:49
sitebuilderLuc Pattyn9-Dec-08 2:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.