We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Getting Column Index of Column Containing ComboBox

Hi, For some reason my code won''t get the column index of the column that contains a ComboBox. Please help!
private void EsiDataSheet_TableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)
		{

if(e.Inner.KeyCode == Keys.Delete)
			{
Record rec = e.TableControl.Table.CurrentRecord;
						if(rec != null)
						{
							int i = e.TableControl.Table.FilteredRecords.IndexOf(rec);
							
							int counter = 0;
							foreach(GridVisibleColumnDescriptor cd in this.TableDescriptor.VisibleColumns)
							{
								counter++;
								GridTableCellStyleInfo style = e.TableControl.Model[i, counter];
								if(style.CellType == "ComboBox")
								{
									this.descriptor = (ClientColumnIndirectLookUp) this.TableControl.Model [i, 7].DataSource;
									DataRow current_row = (DataRow)this.TableControl.Table.CurrentRecord.GetData();
									int id = Convert.ToInt32( current_row[ this.descriptor.MetaAttribute.Class.Layer.PrimaryField.Name ] );
									descriptor.DeleteListFromRelation(id);
																	}
								}
							}

							if(i > 0)
							{
								e.TableControl.Table.CurrentRecord = e.TableControl.Table.FilteredRecords[i-1];
								e.TableControl.Table.CurrentRecord.SetSelected(true);
							}
							rec.Delete();
							e.Inner.Handled = true;	


}

}


2 Replies

TH Thabo July 7, 2005 11:33 AM UTC

>Hi, >For some reason my code won''t get the column index of the column that contains a ComboBox. >Please help! > >
>private void EsiDataSheet_TableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)
>		{
>
>if(e.Inner.KeyCode == Keys.Delete)
>			{
>Record rec = e.TableControl.Table.CurrentRecord;
>						if(rec != null)
>						{
>							int i = e.TableControl.Table.FilteredRecords.IndexOf(rec);
>							
>							int counter = 0;
>							foreach(GridVisibleColumnDescriptor cd in this.TableDescriptor.VisibleColumns)
>							{
>								counter++;
>								GridTableCellStyleInfo style = e.TableControl.Model[i, counter];
>								if(style.CellType == "ComboBox")
>								{
>									this.descriptor = (ClientColumnIndirectLookUp) this.TableControl.Model [i, counter].DataSource;
>									DataRow current_row = (DataRow)this.TableControl.Table.CurrentRecord.GetData();
>									int id = Convert.ToInt32( current_row[ this.descriptor.MetaAttribute.Class.Layer.PrimaryField.Name ] );
>									descriptor.DeleteListFromRelation(id);
>																	
>								}
>							}
>
>							if(i > 0)
>							{
>								e.TableControl.Table.CurrentRecord = e.TableControl.Table.FilteredRecords[i-1];
>								e.TableControl.Table.CurrentRecord.SetSelected(true);
>							}
>							rec.Delete();
>							e.Inner.Handled = true;	
>
>
>}
>
>}
>
>


AD Administrator Syncfusion Team July 7, 2005 12:33 PM UTC

There are several things that may cause your code not to work. First, int i = e.TableControl.Table.FilteredRecords.IndexOf(rec); This i will not necessarily point to the proper grid row if you are grouping or have multiple header rows or have a addnewrow at the top. Doing such things adds rows to the grid, but do not add records to the FilteredRecords collection. Similarily, there may not be a 1-1 correspondance with grid columns and VisibleColumns objects. Now questions for you. Do you know the name of your combobox column? Did you set the style properties (including DataSource, DataMember, and ValueMember) of this column by setting these properties on the grid.TableDescriptor.Columns["???"].Appearance.AnyRecordFieldCell property? If so, code like this should return the DataSource object. object o = e.TableControl.Table.TableDescriptor.Columns["???"].Appearance.AnyRecordFieldCell.DataSource; If you do not know the name of the combobox column, but you did set the CellType using GridColumnDescriptor.Appearance.AnyRecordFieldCell, then you could loop through e.TableControl.Table.TableDescriptor.Columns, looking at GridColumnDescriptor.Appearance.AnyRecordFieldCell.CellType looking for "ComboBox". But you would not loop from 0 to VisibleColumns.Count. You would use a foreach(GridColumnDescriptor col in e.TableControl.Table.TableDescriptor.Columns).

Loader.
Live Chat Icon For mobile
Up arrow icon