using TableLayoutPanel and dynamic Combobox in windows form C# - c#

I need some serious help with this. I've searched on the forums, googled, and expermimented as much as I can....all to no avail.
Here's the problem.
I'm using a TableLayoutPanel to dynamically configure a form based on values from a database.
To the TableLayoutPanel, I dynamically add -
1 Label,
1 Textbox,
1 Button,
1 Combobox
Here's the root of the problem -
If I have 2 or more rows in the TableLayoutPanel, all the Comboboxes
change at the same time.
What do I have to do to only get 1 Combobox to change at a time ?

The datasource is the same, so it treats any change in one combobox connected to the datasource as a change to any other connected comboboxes. To get around that simply make a temporary string array and copy over the information to that array from the original source, from there simply have it be the datasource of the combobox.

Related

How do I connect a binding to a (Winform) ComboBox control to get/set the selection in the control from the binding source?

I have plumbed the deeps of my google-fu to find an answer.
First, I am not simply asking how to bind a combobox to a datasource. It's a bit more than that unless I'm having a serious understanding gap.
On my Winform, I have a DataGridview on the left and on the right I have a panel with values from the selected row on the left. One of those controls on the right is the ComboBox I'm having trouble with. I have my bindingsource and dataview set up and the other controls on the right are working splendidly, except the ComboBox control.
The user, interacting with this ComboBox, should see values such as "Item ABC" and "Item EFG" and the value related to them might be 1234 and 5678. If this was a fully unbound control I'd put an object array of items in. Once I get it working, I'd load that from a different source.
But when I try to DataBindings.Add("??", dataview, "dataviewfield", ...) I can't get the proper value for "??". Runtime debug shows that "SelectedItem.Value" would be the right option, but I get "not found" type exception when I use that. I've tried "SelectedValue" as well, but that didn't work (debug show's it's null & throws no nulls allowed exception).
How can I get that value placed directly into the DataView via the Binding?
Setting the .DataSource simply loses the items and doesn't help at all.
How does one do this? Short of making the ComboBox unbound totally, setting the selectedindex directly and capturing the value when the selected index changes changes - Just seems so clunky to have to do that.
-old programmer
Further Notes: I edited to clarify the placement of the ComboBox.
I have made progress (naturally, only after asking a question does a new avenue pop into my head). I got to thinking I might need a custom binding adapter so started googling that. I found some samples doing what I want.
The foremost problem was I was not using assigning a datasource on the ComboBox, I was simply adding items. When I created a two column dataset and a few rows (could have been anything I suppose) and set that and the two field names as the ComboBox's displaymember and valuemember did the SelectedValue start showing a value (instead of null all the time).
I think that was the problem. The remaining issue is getting the left hand side to re-display/refresh after the change.
When loading the datasource for the DataGridView and the bindingsource, try making them share the same list:
BindingSource1.Datasource = dataset
DataGridView.Datasource = BindingSource1
This should mean that any changes to the data in the bindingsource will also update the DataGridView.
To edit the selected object then just handle the SelectionChanged event and set the BindingSource1.Position to the index of the selected object in the Datasource.

How to disable drag drop row from one datagridview to another?

I have imported "DataGridView" control from Windows form to WPF due to specific reason.
There is customized rows in "DataGridView" like first cell is "ComboBox" with dropdown list and others cells are simple "textBoxes" with readonly mode.
I have placed two customized "DataGridViews" on same Grid(plz refere snapshot).There is one problem when i select comboBox from cell one from any row of "DataGriView1" and hold any item from comboBox,and dragged onto "DataGriView2" then double entries added.
Actually I don't want to allow user to drag drop items from "DataGriView1" to "DataGriView2".
Thanks in advance.
Use AllowDrop property of DataGridView
DataGriView1.AllowDrop = false;

edit multiple rows selected in a GridControl in TextEdits bound to the same bindingsource

My setup:
C#.Net 4.0, Windows Forms, DevExpress 13.1.5 although I doubt its a DX issue
I have a form with a GridControl (with GridView) on the top and a detail area that holds TextEdits and other edits in a LayoutControl below.
Both the grid and the edits below are bound to the properties of the objects contained in a list in the binding source.
The grid is set to ReadOnly, MultiSelect, RowSelect and all its columns are set to ReadOnly, not focusable.
Editing is only happening in the detail area below.
The behavior I want to create:
When multiple rows are selected in the grid the edits below should show the following:
the value of field in question is the same in all selected rows -> show the value
the value of the field in question differs between the rows -> show nothing
if the user writes into the TextEdit while multiple rows are selected:
the value of the edit should update the values of the same field of all the selected rows
Where I am with this:
I'm working on a solution by building a custom BindingSource that would be aware of the selection. It would bind the list of object to the grid and a single object that is not part of the list to the edits. Depending on the selection I would set the properties of that single object or forward its changes to the selected objects in the list.
I got that working for a single property with 2 binding sources and would now extend it to use reflection to do this for all of the public properties. I also want to encapsulate the whole behavior into a class that looks and acts like BindingSource just with that added behavior.
The question:
Is there a simpler way to achieve this? Does something already exist which can do this that I overlooked in either .Net or DevExpress? Are there traps to my approach that I should consider or why I should go about this totally differently?
I think that you can achieve your goal in a simpler manner:
Just bind a single BindingSource with all the data that you need to your grid. That should display the data.
Then, bind the required fields from that same BS do the edits through the DataBindings propriety.
You can then implement a save object (through a control or programatically) so the changes made in the edits are shown in the grid.
To check the grid values, you can use:
//get the handles of the rows
gridView.GetSelectedRows();
//get the value of the desirable cells
gridView.GetRowCellValue(handle, column);
Also, in future projects, consider using the Entity Framework to construct a data-aware model and custom objects based on the elements of your Database.
Hope this helped!

DataGrid not expanding to hold more items when its datasource increases

I have a datagrid in .net compact framework C# and I set its datasource to a list, my problem is when the list size increases the grid does nota dd the new additions, I have to recreate the grid by exiting the form and going back into it to see the new entries. The number of visible rows remains the same, so for example if I went from 10 to 20 entries in the list the datagrid still only shows 10 visible rows, if I exit and re-enter the form the same list ends up giving the datagrid all 20 visible rows..
Your list needs to implement INotifyCollectionChanged. One way to do this is to use ObservableCollection<T>. When you bind to an object that supports INotifyCollectionChanged, the grid will update when records are added or deleted.
If grid cells need to update when properties on the object change, then your object needs to implement INotifyPropertyChanged.
There was no way of actually doing this and I ended up repopulating the database manually every time a cahnge occured then refreshing it to make sure the changes became visible.

DomainUpDown control inside the GridView

I want to add DomainUpDown control inside a DataGridView as a separate column. Each time a new row is added, I want that DomainUpDown control also be added. I also want to know when the user click the DomainUp or DomainDown button in DomainUpDown control for each row. Is it possible or not? I am using language vb.net/C#. I want to do this in winform not in ASP. Any help or suggestion please!!!
All you need to do/know is how to add an unbound column to an already data bound DataGridView, because from your description you are trying to add a column to a grid which already contains other data bound columns. In fact it would be easier if you had such column in the DataTable, also because with unbound columns you need to make a slightly bigger effort to populate and save the data from/to somewhere.
anyway it should be possible, MSDN explains it here: How to: Add an Unbound Column to a Data-Bound Windows Forms DataGridView Control

Categories

Resources