/// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { PactComboBox PactComboBox = new PactComboBox(); ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, PactComboBox); ApplyColumnProperties(PactComboBox); return(PactComboBox); }
private void ApplyColumnProperties(PactComboBox comboBox) { ApplyBinding(SelectedItemBinding, comboBox, PactComboBox.SelectedItemProperty); ApplyBinding(SelectedValueBinding, comboBox, PactComboBox.SelectedValueProperty); ApplyBinding(TextBinding, comboBox, PactComboBox.TextProperty); DataGridHelper.SyncColumnProperty(this, comboBox, PactComboBox.SelectedValuePathProperty, SelectedValuePathProperty); DataGridHelper.SyncColumnProperty(this, comboBox, PactComboBox.DisplayMemberPathProperty, DisplayMemberPathProperty); DataGridHelper.SyncColumnProperty(this, comboBox, PactComboBox.ItemsSourceProperty, ItemsSourceProperty); }
/// <summary> /// Called when a cell's value is to be cancelled, just before it exits edit mode. /// </summary> /// <param name="editingElement">A reference to element returned by GenerateEditingElement.</param> /// <param name="uneditedValue">UneditedValue</param> protected override void CancelCellEdit(FrameworkElement editingElement, object uneditedValue) { PactComboBox textBox = editingElement as PactComboBox; if (textBox != null) { DataGridHelper.UpdateTarget(textBox, PactComboBox.TextProperty); DataGridHelper.UpdateTarget(textBox, PactComboBox.SelectedValueProperty); } }
protected internal override void RefreshCellContent(FrameworkElement element, string propertyName) { DataGridCell cell = element as DataGridCell; if (cell != null) { bool isCellEditing = cell.IsEditing; if ((string.Compare(propertyName, "ElementStyle", StringComparison.Ordinal) == 0 && !isCellEditing) || (string.Compare(propertyName, "EditingElementStyle", StringComparison.Ordinal) == 0 && isCellEditing)) { cell.BuildVisualTree(); } else { PactComboBox PactComboBox = cell.Content as PactComboBox; switch (propertyName) { case "SelectedItemBinding": ApplyBinding(SelectedItemBinding, PactComboBox, PactComboBox.SelectedItemProperty); break; case "SelectedValueBinding": ApplyBinding(SelectedValueBinding, PactComboBox, PactComboBox.SelectedValueProperty); break; case "TextBinding": ApplyBinding(TextBinding, PactComboBox, PactComboBox.TextProperty); break; case "SelectedValuePath": DataGridHelper.SyncColumnProperty(this, PactComboBox, PactComboBox.SelectedValuePathProperty, SelectedValuePathProperty); break; case "DisplayMemberPath": DataGridHelper.SyncColumnProperty(this, PactComboBox, PactComboBox.DisplayMemberPathProperty, DisplayMemberPathProperty); break; case "ItemsSource": DataGridHelper.SyncColumnProperty(this, PactComboBox, PactComboBox.ItemsSourceProperty, ItemsSourceProperty); break; default: base.RefreshCellContent(element, propertyName); break; } } } else { base.RefreshCellContent(element, propertyName); } }
/// <summary> /// Called when a cell's value is to be committed, just before it exits edit mode. /// </summary> /// <param name="editingElement">A reference to element returned by GenerateEditingElement.</param> /// <returns>false if there is a validation error. true otherwise.</returns> protected override bool CommitCellEdit(FrameworkElement editingElement) { PactComboBox textBox = editingElement as PactComboBox; if (textBox != null) { DataGridHelper.UpdateSource(textBox, PactComboBox.TextProperty); DataGridHelper.UpdateSource(textBox, PactComboBox.SelectedValueProperty); return(!Validation.GetHasError(textBox)); } return(true); }
/// <summary> /// Called when a cell has just switched to edit mode. /// </summary> /// <param name="editingElement">A reference to element returned by GenerateEditingElement.</param> /// <param name="editingEventArgs">The event args of the input event that caused the cell to go into edit mode. May be null.</param> /// <returns>The unedited value of the cell.</returns> protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) { //PactComboBoxData CMB = new PactComboBoxData() //{ // IsPartiralData = IsPartiralData, // FeatureID = FeatureID, // CompanyIndex = Convert.ToInt32(CompanyIndex), // Label = strLable, // Mandatory = IsMandatory, // DataType = DataType, // DBColumnName = ColumnName, // Enable = IsReadOnly, //}; PactComboBox textBox = editingElement as PactComboBox; if (textBox != null) { textBox.Focus(); string originalValue = textBox.Text; TextCompositionEventArgs textArgs = editingEventArgs as TextCompositionEventArgs; //if (textArgs != null) //{ // // If text input started the edit, then replace the text with what was typed. // string inputText = textArgs.Text; // textBox.Text = inputText; // // Place the caret after the end of the text. // textBox.Select(inputText.Length, 0); //} //else //{ // // If a mouse click started the edit, then place the caret under the mouse. // MouseButtonEventArgs mouseArgs = editingEventArgs as MouseButtonEventArgs; // if ((mouseArgs == null) || !PlaceCaretOnTextBox(textBox, Mouse.GetPosition(textBox))) // { // // If the mouse isn't over the textbox or something else started the edit, then select the text. // textBox.SelectAll(); // } //} return(originalValue); } return(null); }
/// <summary> /// Helper method which returns selection value from /// PactComboBox based on which Binding's were set. /// </summary> /// <param name="PactComboBox"></param> /// <returns></returns> private object GetPactComboBoxSelectionValue(PactComboBox PactComboBox) { if (SelectedItemBinding != null) { return(PactComboBox.SelectedItem); } else if (SelectedValueBinding != null) { return(PactComboBox.SelectedValue); } else { return(PactComboBox.Text); } }
/// <summary> /// Called when a cell has just switched to edit mode. /// </summary> /// <param name="editingElement">A reference to element returned by GenerateEditingElement.</param> /// <param name="editingEventArgs">The event args of the input event that caused the cell to go into edit mode. May be null.</param> /// <returns>The unedited value of the cell.</returns> protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) { PactComboBox PactComboBox = editingElement as PactComboBox; if (PactComboBox != null) { PactComboBox.Focus(); object originalValue = GetPactComboBoxSelectionValue(PactComboBox); if (IsPactComboBoxOpeningInputEvent(editingEventArgs)) { PactComboBox.IsDropDownOpen = true; } return(originalValue); } return(null); }
PactComboBox pcb = null;//= new PactComboBox() { FeatureID=1 }; /// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { //if (pcb == null) pcb = new PactComboBox() { FeatureID = this.FeatureID }; // SyncProperties(pcb); //ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, textBox); ApplyBinding(pcb, PactComboBox.TextProperty); DataGridComboBoxColumn.ApplyBinding(SelectedValueBinding, pcb, PactComboBox.SelectedValueProperty); pcb.SelectedValue = ((System.Data.DataRowView)(cell.RowDataItem)).Row[((System.Windows.Data.Binding)(SelectedValueBinding)).Path.Path].ToString(); if (pcb.SelectedValue.ToString().Length == 0) { pcb.SelectedValue = null; } return(pcb); }
/// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { PactComboBox textBlock = new PactComboBox(); textBlock.FeatureID = 1; // TextBlock textBlock = new TextBlock(); SyncProperties(textBlock); //ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, textBlock); ApplyBinding(textBlock, PactComboBox.TextProperty); return(textBlock); //TextBox textBox = new TextBox(); //SyncProperties(textBox); //ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, textBox); //ApplyBinding(textBox, TextBox.TextProperty); //return textBox; }
/// <summary> /// Called when a cell has just switched to edit mode. /// </summary> /// <param name="editingElement">A reference to element returned by GenerateEditingElement.</param> /// <param name="editingEventArgs">The event args of the input event that caused the cell to go into edit mode. May be null.</param> /// <returns>The unedited value of the cell.</returns> protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs) { PactComboBox textBox = editingElement as PactComboBox; if (textBox != null) { textBox.Focus(); string originalValue = textBox.Text; //TextCompositionEventArgs textArgs = editingEventArgs as TextCompositionEventArgs; //if (textArgs != null) //{ // // If text input started the edit, then replace the text with what was typed. // string inputText = textArgs.Text; // textBox.Text = inputText; // // Place the caret after the end of the text. // textBox.Select(inputText.Length, 0); //} //else //{ // // If a mouse click started the edit, then place the caret under the mouse. // MouseButtonEventArgs mouseArgs = editingEventArgs as MouseButtonEventArgs; // if ((mouseArgs == null) || !PlaceCaretOnTextBox(textBox, Mouse.GetPosition(textBox))) // { // // If the mouse isn't over the textbox or something else started the edit, then select the text. // textBox.SelectAll(); // } //} return(originalValue); } return(null); }
/// <summary> /// Helper method which returns selection value from /// PactComboBox based on which Binding's were set. /// </summary> /// <param name="PactComboBox"></param> /// <returns></returns> private object GetPactComboBoxSelectionValue(PactComboBox PactComboBox) { if (SelectedItemBinding != null) { return PactComboBox.SelectedItem; } else if (SelectedValueBinding != null) { return PactComboBox.SelectedValue; } else { return PactComboBox.Text; } }
private void ApplyColumnProperties(PactComboBox PactComboBox) { ApplyBinding(SelectedItemBinding, PactComboBox, PactComboBox.SelectedItemProperty); ApplyBinding(SelectedValueBinding, PactComboBox, PactComboBox.SelectedValueProperty); ApplyBinding(TextBinding, PactComboBox, PactComboBox.TextProperty); DataGridHelper.SyncColumnProperty(this, PactComboBox, PactComboBox.SelectedValuePathProperty, SelectedValuePathProperty); DataGridHelper.SyncColumnProperty(this, PactComboBox, PactComboBox.DisplayMemberPathProperty, DisplayMemberPathProperty); DataGridHelper.SyncColumnProperty(this, PactComboBox, PactComboBox.ItemsSourceProperty, ItemsSourceProperty); }
/// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { PactComboBox PactComboBox = new PactComboBox(); ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, PactComboBox); ApplyColumnProperties(PactComboBox); return PactComboBox; }
/// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { //if (pcb == null) pcb = new PactComboBox() { FeatureID = this.FeatureID }; // SyncProperties(pcb); //ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, textBox); ApplyBinding(pcb, PactComboBox.TextProperty); DataGridComboBoxColumn.ApplyBinding(SelectedValueBinding, pcb, PactComboBox.SelectedValueProperty); pcb.SelectedValue = ((System.Data.DataRowView)(cell.RowDataItem)).Row[((System.Windows.Data.Binding)(SelectedValueBinding)).Path.Path].ToString(); if (pcb.SelectedValue.ToString().Length == 0) pcb.SelectedValue = null; return pcb; }
/// <summary> /// Creates the visual tree for text based cells. /// </summary> protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { PactComboBox textBlock = new PactComboBox(); textBlock.FeatureID = 1; // TextBlock textBlock = new TextBlock(); SyncProperties(textBlock); //ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, textBlock); ApplyBinding(textBlock, PactComboBox.TextProperty); return textBlock; //TextBox textBox = new TextBox(); //SyncProperties(textBox); //ApplyStyle(/* isEditing = */ true, /* defaultToElementStyle = */ false, textBox); //ApplyBinding(textBox, TextBox.TextProperty); //return textBox; }