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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Getting Column Index of Column Containing ComboBox

Thread ID:

Created:

Updated:

Platform:

Replies:

31421 Jul 7,2005 11:31 AM UTC Jul 7,2005 12:33 PM UTC WinForms 2
loading
Tags: GridControl
Thabo
Asked On July 7, 2005 11:31 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, 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;	


}

}


Thabo
Replied On 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;	
>
>
>}
>
>}
>
>

Administrator [Syncfusion]
Replied On 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).

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;