Home » SQL Server

Combobox + Textbox in GroupBox

In my project, which search data from my database, I have some parameters for searching. For each parameter I have a pair: combobox with a list of parameters for the selection and textbox to display the selected parameter.
All this works fine.
But when I put such a pair (combobox + textbox)  in a groupbox, I get a searching without this parameter. If I put the combobox + textbox out of  the groupbox again , then everything works fine.

I can solve this without groupboxes but I am interested in why this happens?



4 Answers Found


Answer 1

You haven't explained how you are extracting the data out of your controls.

Are you using the Find method?  That doesn't look deeply through nested controls. You need to run that on the GroupBox, not the Form.  (It is also possible to write a more powerful "recursive" Find method that looks through everything... write back if you need more help.)




Answer 2

For me it is  difficult to understand what you say. Maybe I can ask more generally:         Is there a difference in the behavior of controls if they are located within or outside the  groupbox?

Thanks. Zlatkodo


Answer 3

No. Those controls should not behave any differently based on their container.

What does change is how to find them as BC mentioned.

If you look for the controls on the form, you won't find them because the controls are stored in a hierarchy based on their container. See this link for more information.


Hope this helps.


Answer 4

I still need a little help, please. Part of my code for Form1 is next:



ForEach ctl As Control InMe.Controls


IfTypeOf ctl Is TextBox Then


If ctl.Text <> ""And ctl.Tag.ToString <> "Di"And ctl.Tag.ToString <> "L"And ctl.Tag.ToString <> "kW"Then

clausestring = clausestring &

CStr(ctl.Tag) & " = @" & CStr(ctl.Tag) & " and "


"@" & ctl.Tag.ToString, ctl.Text)











 How the code should look like if I want to search:
- full Form1 including all GroupBoxes? 

- just GroupBoxes ?
Thanks in advance.




Hi All.

I filter combobox list by input textbox value. But I would like to display combobox value automatically if result of filter give me only one value in the combobox list.



I have a problem with populating dataGridView. Here`s the issue: I have a textBoxColumn and a comboBoxColumn. How to populate them both in a runtime?

I just need a simple example. 

I create them like this:

privatevoid CreatingDGW()
   DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
   column1.ReadOnly = true;
   column1.Name = "column1";
   column1.Resizable = DataGridViewTriState.False;
   //column1.SortMode = DataGridViewColumnSortMode.Automatic;
   column1.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
   column1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
   column1.HeaderText = "TextBoxName";
   column1.Width = 80;
   DataGridViewComboBoxColumn column3 = new DataGridViewComboBoxColumn();
    column2.Name = "column2";
    column2.HeaderText = "Model";
    column2.Resizable = DataGridViewTriState.False;
    column2.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft;
    column2.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
    column2.DropDownWidth = 90;
    column2.MaxDropDownItems = 4;    
    column2.Width = 100;
    column2.FlatStyle = FlatStyle.Standard;

   //and some additional settings for the dgw


Now when I am populating I, the code goes through well, but when the form shows up, there is an error repeating constantly. I fill a row with only one value (for textbox and comboBox), but there is no value in comboBox at all- and that error as mentioned is poping up every time I go with a mouse over dgw, and the error is: DataGridViewComboBoxCell value is not valid!

As said, i just need a simple example of how to populate dgw which has a textBox and comboBox.


I'm trying to validate a textbox, so that when a combobox on the form has a particular value the textbox must contain text.

I've created a validation rule with a property to pass in the selecteditem for the combobox, but when trying to set this in Xaml I get the exception "A 'Binding' can only be set on a DependencyProperty of a DependencyObject." What am I doing wrong?

Here's the textbox:

<TextBoxx:Name="ImportNotes"TextWrapping="Wrap"Height="100"><TextBox.Text><BindingPath="Notes"UpdateSourceTrigger="Explicit"><Binding.ValidationRules><val:RequiredFieldForArchivedImportRuleImportStatus="{Binding ElementName=CurrentStatus, Path=SelectedItem}"></val:RequiredFieldForArchivedImportRule></Binding.ValidationRules></Binding></TextBox.Text></TextBox>

The combobox's itemssource is set in code.  It is a list of the following type:

publicclass ImportStatus : DependencyObject
    publicint ID { get; set; }

    publicstaticreadonly DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof(object), typeof(ImportStatus));
    publicstring Name
      get { return (string)GetValue(NameProperty); }
      set { SetValue(NameProperty, value); }

    public ImportStatus(int id, string name)
      ID = id;
      Name = name;

The combobox is simply



Hi All.

In my form I have TextBox and ComboBox bounded to DataSet. When I type in, for instance 45, data to TextBox it filter list of ComboBox fill by TableAdapter1. If I enter in TextBox value that not esists TableAdapter1, for instance 4545, so ComboBox will fill by TableAdapter2. It is work fine. My problem become when enter 4545 and got according list and then return back to TextBox and type 45. So after that I'm getting first value from list TableAdapter2. Not like expected according value from TableAdapter1. That is code of procedure

PrivateSub SetAdm_No(ByVal Adm_No AsString)

  PatTableAdapter.FillBy(DataSet1.Pat, Me.AdmNoTextBox.Text)

  Me.cvPat = CollectionViewSource.GetDefaultView(DataSet1.Pat)

  IfMe.cvPat.Count > 0 ThenIfMe.cvPat.Count < 2 ThenMe.PatComboBox.SelectedIndex = 0

   ElseMe.PatComboBox.ItemsSource = Me.cvPat

   EndIfElseIfMe.cvPat.Count = 0 Then


   Me.cvNewPat = CollectionViewSource.GetDefaultView(DataSet1.NewPat)

   Me.PatComboBox.ItemsSource = Me.cvNewPat

It might be a bit premature to ask here, but here's what I've done.
I've downloaded VS2008EE and I've made myself a little password generator program that accepts an integer value from the command line which it uses as the length of the password it generates. Cool little console thing.

What I'd like to do now is create a Windows Forms Application and have a combobox with which to choose the password length, a button to trigger the password generation, displaying the password in a textbox. I've built the form. I need to somehow graft the password class into my form (somewhere?), figure out the combobox populating thing and rig up the button. 
There's likely a tutorial/walkthrough somewhere on populating combobox's, and that's probably what I'll learn next. I suppose pressing the button is going to be akin to executing my old main() function, somehow redirect cout to the textbox ... ?

If someone has a nice gentle way of explaining it ... please. 

I can use this code when initialising the combox component to populate it with a few entries and default to the first entry.
this->lengthComboBox->Items->AddRange(gcnew cli::array< System::Object^ >(3) {8, 10, 14});

I can set the textbox to display the currently selected combobox entry with:

System::Void genButton_Click(System::Object^ sender, System::EventArgs^ e)


    this->passTextBox->Text = this->lengthComboBox->Text;


I should be good from here. Thanks!

this->lengthComboBox->SelectedIndex = 0;


Hi All.

I found sample http://www.codeproject.com/KB/WPF/WPFAutoCompleteTextbox.aspxAutoComplete ComboBox where data is hardcoded in the code. I would like to use AutoComplete ComboBox binded to dataset. I don't have a problem binding data to ComboBox but I have problem if need that combobox autocomplete and filtered listbox. That is bit of code which I found


    textBox1.AddItem(New AutoCompleteEntry("Toyota Camry", "Toyota Camry", "camry", "car", "sedan"))
    textBox1.AddItem(New AutoCompleteEntry("Toyota Corolla", "Toyota Corolla", "corolla", "car", "compact"))
    textBox1.AddItem(New AutoCompleteEntry("Toyota Tundra", "Toyota Tundra", "tundra", "truck"))
    textBox1.AddItem(New AutoCompleteEntry("Chevy Impala", Nothing)) ' null matching string will default with just the name
    textBox1.AddItem(New AutoCompleteEntry("Chevy Tahoe", "Chevy Tahoe", "tahoe", "truck", "SUV"))
    textBox1.AddItem(New AutoCompleteEntry("Chevrolet Malibu", "Chevrolet Malibu", "malibu", "car", "sedan"))

My dataset has Customers table and I'm binding data in Loaded procedure like

PrivateSub AutoComplete_Loaded(ByVal sender AsObject, ByVal e As System.Windows.RoutedEventArgs) HandlesMe.Loaded 
  Me.cvCustomers = CollectionViewSource.GetDefaultView(CtrlNWindDataSet.Customers)  <br/>  Me.textBox1.DataContext = Me.cvCustomers 

How to modify code to substitute hardcoded data to binding with dataset ?



Hey all,


If I have a TextBox that is already two-way bound to something, but I also want it so when a ComboBox SelectedItem changes, then the TextBox's Text property is set to the new SelectedItem.


Here's what I have so far, I added the comment where the TextBox is, which I would like to also be bound to the ComboBox below this.


<!--Parameters--><ListViewGrid.Row="2"DataContext="{Binding ScriptParameters}"ItemsSource="{Binding}"><ListView.View><GridViewAllowsColumnReorder="True"><GridViewColumnHeader="Name"DisplayMemberBinding="{Binding ObservableKeyValuePair.Key}"/><GridViewColumnHeader="Value"><GridViewColumn.CellTemplate><DataTemplate><!--This is two-way bound to my MVVM's Value property, but I also want it to
                      change when the user selects a new item in the ComboBox below this (PossibleValues)--><TextBoxText="{Binding ObservableKeyValuePair.Value, Mode=TwoWay}"MinWidth="100"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn><GridViewColumnHeader="Possible Values"><GridViewColumn.CellTemplate><DataTemplate><ComboBoxItemsSource="{Binding PossibleValues}"SelectedItem="{Binding ObservableKeyValuePair.Value}"/></DataTemplate></GridViewColumn.CellTemplate></GridViewColumn></GridView></ListView.View></ListView>


I want to have a button on my page where a textbox.... becomes editable but it does so by turning into a combo box so that only a predefined set of values can be set into the textbox.

I know I can do this easily by drawing a combobox in the same place as the text box and making it not visible....... then when the edit button is clickd I can make it appear while making the textblock disappear.

But I was wondering... from a purely technical standpoint. Say I had several of these controls. If I did that for each of them where I needed this functionality I would have to draw several invisible controls at load time. Would it be more efficient to do this from code-behind........ and only draw the combobox control to the canvas when it was needed?

In a Windows form vb.net. I have a bounded combobox with the "display" and "value" member mapped to a field in a dataset. The combobox is set to "DropDown" mode ie user can key in the value to the textbox or simply selecting an item from the droplist. However I want to put in a "Validating" event to check the value entered directly by the user is one of the value available in the droplist. The "display" member is mapped to a field "store number" and the "value" member is mapped to the "store_id". I want to warn user if the "store number" entered is not exist in the droplist. 

PropertiesGrid.Rows(1).Cells.Item(1).Gettype returns System.Windows.Forms.DataGridViewTextBoxCell"} System.Type

how could I turn that into a combobox for that specific cell - row 1,  column 1?

Thank you,


I'm developing a wpf windows app ( my first one ) and I can't manage to solve this problem I have.

Take two  comboboxes, each with the selectedValue bound to a path in the window's DataContext. The DataContext is set to a table in a DataSet.

SelectedValue="{Binding Path=brandID}"
SelectedValue="{Binding Path=modelID}"
And on the window loaded event I setup the ItemsSource for them:
privatevoid Window_Loaded(object sender, RoutedEventArgs e) 
this.DataContext = this.ProductsDataSet.products; 
// Lookup values from all brands
this.ddlBrand.ItemsSource = this.ProductsDataSet.brands;  
// Lookup values from all models
this.ddlModel.ItemsSource = this.ProductsDataSet.models;  
// setting up the CollectionView
this.view = (CollectionView)CollectionViewSource.GetDefaultView(this.ProductsDataSet.products);        

What I need is when I select a value from ddlBrand, the values in ddlModel to be limited to the ones available to the specific brand selected. In the same time, the SelectedValue for the models ( which is of type int) is to be set to the value in the products table.
I've tried to implement this in several ways ( setting up the ItemsSource ddlModel on the SelectionChanged event of ddlBrand, setup a CustomFilter for the BindingListCollectionView of ddlModel - in the same event, the previous 2 versions in different events and variations etc. ) no success. Everytime I modify the source or the view of ddlModel the SelectedValue binding setup in XAML is lost ( I've tried rebinding in code) . Everytime I change the product I'm viewing the selection in ddlModel is lost.
I believe this is a simple common task, so there must be something I'm missing.  It's been almost 2 days since I'm strugling with this ( productive, huh? ). Can someone share some knowledge?

PS: The data is taken from an access database. DataSet created with drag and drop in the designer. Tables: products(productID, brandID, modelID, version, etc), brands (brandID, brandName), models (modelID, modelName ) . The navigation is like in How Do I: Create a Simple Data Entry Form in WPF



I am trying to change the displayed value of a comboBox based on the value of another comboBox at the click of a button.  Both comboBoxes are already populated.

I am using C# language.  Here is a code snippet:

private void updateButton_Click(object sender, EventArgs e)
       if (Text.(this.floorComboBox.Text) == FloorName1)
        this.beamComboBox.Text = "BeamName1";
but an error is coming up on Parse and I'm not sure whether the code is correct anyway.

Any help appreciated.

Best regards,



Hi everybody!

I'm developing a WPF application that needs a combobox updating another combobox items when selection changes.

I isolated the code and the problem is still there, when i change the first selection and then click the other it takes a lot of time (IMHO) 


namespace TestCombobox
 ///<summary>/// Interaction logic for MainWindow.xaml///</summary>publicpartialclass MainWindow : Window
  private List<string> methodsList;
  private Dictionary<string, List<string>> dict;

  public MainWindow()

   dict = new Dictionary<string, List<string>>();

   for(int i=0; i<20; i++){
    List<string> current = new List<string>();
    dict.Add(i.ToString(), current);
    for (int j = 0; j < 10; j++)
     current.Add(new StringBuilder().AppendFormat("{0} - {1}", i, j).ToString());

   types.ItemsSource = dict.Keys;
   types.SelectedIndex = 0;
   dict.TryGetValue(types.Items[0] asstring, out methodsList);
   methods.ItemsSource = methodsList;

  privatevoid types_SelectionChanged(object sender, SelectionChangedEventArgs e)
   dict.TryGetValue(types.Items[((ComboBox)sender).SelectedIndex] asstring, out methodsList);
   methods.ItemsSource = methodsList;


And its XAML:


Anyone knows why it's so slow?



Is there a simply way to can change the Combobox drop down box's background without override whole combobox controltemplate?

the default combobox dropdown box background is white. we like to customize it. thx!




How to update data of a ComboBox after selecting an item in another ComboBox. My application is a Silverlight Business Administration and I do not use the design patternMVVM (I try to learn).

Each ComboBox is filled with a query(Ria Service).

There is a way to do that.



I am trying subcategory datagridviewcombobox column changed items based on category combobox selected value.. any help me


thanks in advance...

When I move a button from one groupbox to another, it's click function is "lost". And I'll haveto change it back manually. Cause if I just
doubleclick it and it takes me from the design window, to the code it's button_click_1.

How come it does that? Any way to stop it from doing so?


I have a Visual Studio 2008 C++ application for Windows Mobile 6. Given a screen point, I need to know the child-most window at that point. So, I implemented a function as below:


HWND GetChildMost( HWND window, const POINT& screen_point )
  HWND child = ::ChildWindowFromPoint( window, screen_point );
  if( NULL == child || child == window )
    return window;
  return GetChildMost( child, screen_point );

// locate the child-most window at the given point
HWND target = GetChildMost( ::WindowFromPoint( screen_point ), 
              screen_point );

This works perfectly except in the case where there is a groupbox around a set of controls. For example:


IDC_MY_FORM DIALOG 0, 0, 161, 152
FONT 8, "MS Sans Serif"
  LTEXT      "My Control",IDC_STATIC,8,115,37,8
  GROUPBOX    "",IDC_STATIC,4,37,154,98

In this case, if I provide the screen coordinates for the static text labeled "My Control", ::WindowFromPoint() will always return the handle for the group-box and the first call to ::ChildWindowFromPoint() will return NULL. My target window will, therefore, always be the group box.

Is there a way around this issue?




Using the Windows form designer, I am trying to improve the appearance and user interface for a windows form with about 100 databound textboxes. To help organize the screen, I grouped the controls with 8 group boxes.  The form displays OK in the IDE/designer, but the form will not display when executed.

Has anyone else had similar problems using large numbers of controls, panels, and group boxes?

Thanks, -BGood


I am developing a Windows application in C# in Visual Studio 2008 (on an XP Version 2002 Service Pack 3 computer) that must look and behave like an existing MS-DOS application. In order to make the window borders look like the existing window borders I have derived a new GroupBox control from the Windows.Forms.Groupbox control. This control draws a border using 2 concentric rectangles and also allows the title to be aligned on the left, center or right.

The forms contain other Windows controls that look like MS-DOS text and I don't want the mouse to be able to select any of these controls. To prevent mouse interaction on the forms I have placed a Panel on the form, I make it cover the form setting the Dock property to Fill, bringing the panel to the front and make the panel transparent using the SetWindowLong function. There is no mouse interaction on the form as required but my group box is not being drawn. If I cover the form and then expose it, the groupbox can been seen.

I have been doing some experiments by having a standard .Net groupbox on the form and a smaller panel that covers part of a label, the .Net groupbox and part of my groupbox. When the application runs it shows the label, the .Net groupbox and the uncovered part of my groupbox. I have even commented out the OnPaint method in my groupbox class so that the .Net class should draw the control and part of my groupbox is still not drawn. That really puzzled me because I thought that it would behave like the standard Microsoft control.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure