View Full Version : Edit datagrid
Mitsuki
05-13-2006, 09:35 AM
Hi
I am retreiving items from Access Database to a datagrid
and it is working ... I have a status column, what I want to do it that allow the user to change this status and when the status is changed I wanted to be saved in the main table "tblItems" and in the status table "tblStatus"
Can someone please tell me how can I do that???
handshakeit
05-15-2006, 11:40 AM
Hi
I am retreiving items from Access Database to a datagrid
and it is working ... I have a status column, what I want to do it that allow the user to change this status and when the status is changed I wanted to be saved in the main table "tblItems" and in the status table "tblStatus"
Can someone please tell me how can I do that???
Yoou need to define a relation between the two tables
and same in the dataset
vinyl-junkie
05-15-2006, 02:15 PM
Here (http://www.c-sharpcorner.com/asp/Code/DBGridEditingPA.asp) is a good example of how to edit a datagrid.
Mitsuki
05-16-2006, 06:47 AM
I tried it but my update doesnt work
vinyl-junkie
05-16-2006, 01:03 PM
Post your code. It's impossible to help you without it. ;)
Malith
05-18-2006, 09:52 AM
this is good coding pl try this
// Set column styles
// Define comboCountry variable as a ComboBoxColumn column style object of DataGridComboBoxColumn class
internal DataGridComboBoxColumn comboCountry;
// Define comboCapital variable as a ComboBoxColumn column style object of DataGridComboBoxColumn class
internal DataGridComboBoxColumn comboCapital;
...........
// Set column styles
// Set datagrid ComboBox ColumnStyle for Country field
comboCountry = (DataGridComboBoxColumn) new DataGridComboBoxColumn(ref Dictionary, 0, 0, true, false, false, DataGridComboBoxColumn.DisplayModes.ShowDisplayMember, 0);
comboCountry.Leave += new DataGridComboBoxColumn.LeaveEventHandler(this.comboCountry_Leave);
TblStyle.GridColumnStyles.Add(comboCountry);
TblStyle.GridColumnStyles[0].MappingName = "Country";
TblStyle.GridColumnStyles[0].HeaderText = "Country";
TblStyle.GridColumnStyles[0].Width = 165;
TblStyle.GridColumnStyles[0].NullText = string.Empty;
// Set datagrid ComboBox ColumnStyle for Capital field
comboCapital = (DataGridComboBoxColumn) new DataGridComboBoxColumn(ref Dictionary, 1, 1, true, false, false, DataGridComboBoxColumn.DisplayModes.ShowDisplayMember, 0);
comboCapital.Leave += new DataGridComboBoxColumn.LeaveEventHandler(this.comboCapital_Leave);
TblStyle.GridColumnStyles.Add(comboCapital);
TblStyle.GridColumnStyles[1].MappingName = "Capital";
TblStyle.GridColumnStyles[1].HeaderText = "Capital";
TblStyle.GridColumnStyles[1].Width = 165;
TblStyle.GridColumnStyles[1].NullText = string.Empty;
...........
// "Country" datagrid cell has been left. Update corresponding "Capital" cell value in the current datagrid row
private void comboCountry_Leave(object sender, System.EventArgs e)
{
System.Data.DataRow[] Capital = Dictionary.Select("Country='" + comboCountry.combo.Text + "'");
DataGrid1[DataGrid1.CurrentRowIndex, 1] = Capital[0][1];
}
// "Capital" datagrid cell has been left. Update corresponding "Country" cell value in the current datagrid row
private void comboCapital_Leave(object sender, System.EventArgs e)
{
System.Data.DataRow[] Country = Dictionary.Select("Capital='" + comboCapital.combo.Text + "'");
DataGrid1[DataGrid1.CurrentRowIndex, 0] = Country[0][0];
}
Mitsuki
05-18-2006, 02:36 PM
Thank you so much it works now
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.