/// <summary> /// Returns selected vlue from the combobox casted to string. /// </summary> /// <param name="source">Source combobox to extract value.</param> /// <returns> /// Returns selected vlue from the combobox casted to string. /// </returns> private string GetSelectedValue(ComboBox source) { string value; if (source.SelectedItem is KeyDisplayValuePair) { KeyDisplayValuePair item = source.SelectedItem as KeyDisplayValuePair; value = item != null ? item.Key as string : String.Empty; } else { value = source.SelectedItem as string; } return(value); }
/// <summary> /// Sets flags check state for each fkag. /// </summary> private void FillFlags() { // Iterate through availabel flags. For each item key is the column name // in the column data row to check for the flag value. for (int i = 0; i < flagsList.Items.Count; i++) { // Get item for the flag. KeyDisplayValuePair item = flagsList.Items[i] as KeyDisplayValuePair; // If value of the item is true, set cheched state if (item != null && item.Key != null && DataInterpreter.GetSqlBool(ColumnRow, item.Key.ToString())) { flagsList.SetItemCheckState(i, CheckState.Checked); } else { flagsList.SetItemCheckState(i, CheckState.Unchecked); } } }
/// <summary> /// Handles changes in the checked list box with flags. /// </summary> /// <param name="sender">Event sender. Must be flagsList.</param> /// <param name="e">Information about event.</param> private void OnFlagsListItemCheck(object sender, ItemCheckEventArgs e) { // Validate event data if (e == null) { Debug.Fail("Empty event data!"); return; } // Extract item KeyDisplayValuePair item = flagsList.Items[e.Index] as KeyDisplayValuePair; if (item == null || String.IsNullOrEmpty(item.Key as string)) { Debug.Fail("Empty item!"); return; } // Set row value SetAttribute((string)item.Key, e.NewValue == CheckState.Checked ? DataInterpreter.True : DataInterpreter.False); }
/// <summary> /// Handles notification on command combobox selection changed. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">Detailed information about event.</param> private void OnActionChanged(object sender, EventArgs e) { // If updates locked or no selected key, ignore event if (lockUpdate || SelectedKey == null) { return; } // Get and validate sender combobox ComboBox cont = sender as ComboBox; if (cont == null | !(cont.Tag is string)) { Debug.Fail("Invalid event sender!"); return; } // Get slected item and extract value KeyDisplayValuePair item = cont.SelectedItem as KeyDisplayValuePair; object value = item != null ? item.Key : null; // Set attribute DataInterpreter.SetValueIfChanged(SelectedKey, cont.Tag as string, value); }