Click here to Skip to main content
15,904,416 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sound Async?? Pin
Muammar©30-Dec-06 21:13
Muammar©30-Dec-06 21:13 
GeneralRe: Sound Async?? Pin
Muammar©30-Dec-06 21:14
Muammar©30-Dec-06 21:14 
Questionhow can ı get URL ? Pin
asay26-Dec-06 4:33
asay26-Dec-06 4:33 
AnswerRe: how can ı get URL ? Pin
Niiiissssshhhhhuuuuu26-Dec-06 17:21
Niiiissssshhhhhuuuuu26-Dec-06 17:21 
QuestionWindows CardSpace effect Pin
Kel_26-Dec-06 4:07
Kel_26-Dec-06 4:07 
AnswerRe: Windows CardSpace effect Pin
WillemM26-Dec-06 4:18
WillemM26-Dec-06 4:18 
GeneralRe: Windows CardSpace effect Pin
Kel_26-Dec-06 4:23
Kel_26-Dec-06 4:23 
QuestionDynamic value for new row in DataGrid Pin
AndrusM26-Dec-06 3:15
AndrusM26-Dec-06 3:15 
I have .NET 1 WinForms dataGrid bound to dataTable.
dataTable has primary key field.
dataTable constraints should be checked during editing.

If user moves out from new row, an error occurs.
RowChanging event does not fire before error.

How to fill field with dynamic default value when new row is added to DataGrid ?

To reproduce:

1. Run code
2. Enter data to first column only
3. Press Down Arrow

Observed error:

---------------------------
Committing the row to the original data store has caused an error.
---------------------------
Value Column 'Column2' does not allow nulls. Do you want to correct this value?

Expected:

No error. Primary key column should be filled.

using System.Windows.Forms;
using System.Data;
static class Program {
	static void Main() {
		Application.Run(new Frm());
		}
	}

class Frm: Form {
	public Frm() {
		DataTable table = new DataTable();
		DataColumn[] keys = new DataColumn[1];
		DataColumn column1 = new DataColumn();
		DataColumn column2 = new DataColumn();
		DataGrid grid = new DataGrid();
		
		grid.Dock = DockStyle.Fill;
		table.Columns.Add(column1);
		table.Columns.Add(column2);
		keys[0] = column2;
		table.PrimaryKey = keys;
		Controls.Add(grid);
		table.RowChanging += new DataRowChangeEventHandler(OnRowChanging);
		grid.SetDataBinding(table, "");
		}

	private void OnRowChanging(object sender, DataRowChangeEventArgs e) {
		if (e.Action == DataRowAction.Add) {
			string pk = e.Row.Table.PrimaryKey[0].ColumnName;
			if (e.Row[pk] == null)
				e.Row[pk] = new System.Guid();
			}
		}
	}



Andrus

AnswerRe: Dynamic value for new row in DataGrid Pin
Nader Elshehabi26-Dec-06 8:02
Nader Elshehabi26-Dec-06 8:02 
GeneralRe: Dynamic value for new row in DataGrid Pin
AndrusM27-Dec-06 0:11
AndrusM27-Dec-06 0:11 
GeneralRe: Dynamic value for new row in DataGrid Pin
Nader Elshehabi27-Dec-06 3:52
Nader Elshehabi27-Dec-06 3:52 
GeneralRe: Dynamic value for new row in DataGrid Pin
AndrusM27-Dec-06 4:06
AndrusM27-Dec-06 4:06 
GeneralRe: Dynamic value for new row in DataGrid Pin
Nader Elshehabi27-Dec-06 5:39
Nader Elshehabi27-Dec-06 5:39 
QuestionHow to handle mouse move in combobox Pin
prabhakaranns26-Dec-06 3:14
prabhakaranns26-Dec-06 3:14 
QuestionText Coloring in richTextBox Pin
Moham'd26-Dec-06 0:47
Moham'd26-Dec-06 0:47 
AnswerRe: Text Coloring in richTextBox Pin
Kishore Ramakrishnan26-Dec-06 1:50
Kishore Ramakrishnan26-Dec-06 1:50 
GeneralRe: Text Coloring in richTextBox Pin
Moham'd26-Dec-06 8:05
Moham'd26-Dec-06 8:05 
Questionget 50 files from directory . Pin
justintimberlake26-Dec-06 0:43
justintimberlake26-Dec-06 0:43 
Questionhow to configure my iis to send email from my Asp.net website (in my iis) ? Pin
hdv21226-Dec-06 0:37
hdv21226-Dec-06 0:37 
AnswerRe: how to configure my iis to send email from my Asp.net website (in my iis) ? Pin
Muammar©26-Dec-06 3:43
Muammar©26-Dec-06 3:43 
QuestionDrag drop [toolbar]toolstrip onto form from its container Pin
GunaChinna25-Dec-06 23:59
GunaChinna25-Dec-06 23:59 
QuestionHow or is it possible...?? Pin
Besinci25-Dec-06 23:58
Besinci25-Dec-06 23:58 
AnswerRe: How or is it possible...?? Pin
Nader Elshehabi26-Dec-06 7:55
Nader Elshehabi26-Dec-06 7:55 
GeneralRe: How or is it possible...?? Pin
Besinci26-Dec-06 8:36
Besinci26-Dec-06 8:36 
GeneralRe: How or is it possible...?? Pin
Nader Elshehabi26-Dec-06 18:24
Nader Elshehabi26-Dec-06 18:24 

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.