WinForm add new element to form between existing elements - c#

I have the following form:
1) Label -> ComboBox
2) Label -> ComboBox
3) Label -> RadioBox
4) additional items
I want to insert a new ComboBox between row 2 to row 3 and to move other elements.
How can i do it? is the best solution to create a hidden ComboBox and then make it visible? or should i create a dynamic ComboBox?
Thanks!

I would put my controls into a TableLayoutPanel and then you can simply insert new RowStyles into it. And Columns for that matter, if need be.
As for moving things, you can always reassign the Row and Column indexes for the controls, effectively assigning them to new grid cells within the TableLayoutPanel.

Related

Adding a fixed number of rows in datagridview in c# in the .cs design form

I am trying to create a datagridview with 25 rows containing three columns and next option for going to next records of a local database,containing employee name id.employee and view profile button.but cant add a single row from the tool box..how is it possible to do in the design form?
Drag drop DataGridView control.
In Form_Load event write:
datagridView1.RowCount = 25;

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;

using TableLayoutPanel and dynamic Combobox in windows form 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.

How add columns to a row in Grid in wpf

I have a MainGrid in Wpf (not a DataGrid) it has 3 rows(0.1 and 2) i have made rows using xaml at design time now at run time behind a menu button i want to add 2 column to row 1 of the main grid.
The hard part is that only break the row 1 into 2 columnn and not the whole Grid.
i know that to add new rows and columns one can use rowdefination and columndefination but
couldnt find anything here:
MainGrid.RowDefinitions.ElementAt(1).SetValue...;
Thanks
Why don't you add a Grid with 1 row and 2 columns to that row instead. And put your contents in that Grid. That will be easier.
make the column span = 2 for all the controls that you add in row 2 and 3...

How to add a new row into datagridview using grid only. i.e by showing textboxes and add button in WinForm

I want to add a new row to a datagridview such that when a user clicks on new button , a new is is generated with few textboxes and combo boxes and after filling up all the details he save the info by clicking on save button.
EDIT
I want to do it like it is seen in gridview(Template Fields) in asp.net
I am looking for same kind of functionality.
Since I'm not sure exactly how you want to achieve this.. I would have a hidden panel with your text boxes, ...etc, show the panel when the new button is clicked. After all information is entered into the fields, click the save button. Assuming that you will be inserting this information into a table, after the row is inserted, call the stored procedure to get the desired records from the table being displayed in the grid.
Assuming your _dataGridView.Columns collection is not null and contains a template of the rows you wish to add, it is as simple as something like this:
foreach(var item in _collection)
{
_dataGridView.Rows.Add(item.Foo, item.Bar);
}
In order for this to work, you will have had to design your Columns collection in the VisualStudio designer or programatically add DataGridViewTextBoxColumn objects to the Columns collection.
In the example above, I added two DataGridViewTextBoxColumn objects to the _dataGridView.Columns collection and then populated the datagrid from a List of my object that contained a 'Foo' and a 'Bar'.
EDIT
Have you checked out the DataGridView FAQ? The information about using the DataGridView in unbound mode may help you.
HTH

Categories

Resources