WPF Make layout dynamically - c#

I want to make layout dynamically.
For example, When I drag and drop a image, 1 image appears on the box.
When I drag and drop another image, box divide into 2 box (dynamically divide into two).
My question is, what layout should I use (stack panel, grid, or something else) and How to I make layout dynamically using code?
I know question is a little vague but I'm not so good at WPF so please understand Thx.

I would use a GridView and so you can add column or row.
DataGridViewTextBoxColumn trackPositionTextBox = new DataGridViewTextBoxColumn();
trackPositionTextBox.HeaderText = "Track Postion";
trackPositionTextBox.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridViewSamples.Columns.Add(trackPositionTextBox);
That's to add a Column in a DataGridView.
dataGridViewSamples.Row.Add()
That's to add a row.
I'm also not the best in wpf, but I hope it was helpful.

If you don't need any animation, you could simple add new columns and rows to your WPF-Grid, while drop an image.
Maybe this help you: How to add rows and columns to a WPF Grid programmatically

Related

Customized datagridview Rows

Check the above picture. I need to know how to include a picture in a datagridview textbox row.
I would also like to know if we can add text in it and so that the picture has a click event too.
Can someone explain to me how to achieve this type of datagridview row?
From the picture you can see that it doesn't consume space for a datagridview in advance. When the row is added the datagridview size increases. How do I achieve this?

Change column view DataGridView

The title may be a bit confusing, and I'll try my best in trying to explain my problem.
I have a horizontally scrollable datagridview and when I click a button on the menu bar, I want the datagridview to move the view to the specified column, while still having all columns still visible.
So For example I click on Fish, and then the datagridview should scroll/position itself to the first mention of Fish in the columns to show a section of the view all related to Fish, while still maintaining all other columns not related to Fish and viewable.
What I would like to know is, is the moving of the position of the view possible to do? I didn't know what to search up, and more or less the results of the search included re-ordering of the columns, which I do not want.
For a DataGridView with windows form --- give your cell to Particuler Id.
Like you want to assign a one column with Fish then
row.Cells["Name"].Value = Fish.Id;
and then on click event give focus to this id.
Note:- for a better solution post your question with your code.
thanks
Replace fish to your search text and try it.
List<DataGridViewColumn> Cols = dataGridView1.Columns.Cast<DataGridViewColumn>().Where(c => c.HeaderText.Contains("fish")).ToList();
if (Cols.Count > 0)
{
dataGridView1.FirstDisplayedScrollingColumnIndex = Cols[0].Index;
}
Above code will scroll down datagridview horizontally to show searched text in column names.

How to bind List<T>-item to a row of a Grid and get clicked item in code?

I'm looking for a solution to bind a List<customclass> to a ListView (or GridView?), where I can modify the way how the items are displayed, for example, the customClass has a name and a picture and I want to display at the left half of the row in the listview the picture and on the right half the text in a textblock.
Is this possible? If yes, how/where should I start? I'm very new at WPF/XAML so it is very hard to understand how data binding and this stuff works.

Equivalent for DataGrid RowDetails template in Winforms DatagridView

I need to create an expander in my datagridview that adds additional info about that row to the datagridview when selected, and hides the same when collapsed.
This is possible by creating RowDetails templates in WPF, but can I do something similar in winforms datagridview? A workaround I'd thought of was dynamically adding objects to the datagridview on expand/collapse, but it won't work in this case because the number, type, arrangement of columns is very different for the details rows than the data rows.
Can RowTemplate possibly help? All examples I've seen thus far use rowtemplate only to fix height, width etc of rows in a datagridview and nothing else.
You can use ToolTip for selected row if you want to show additional data info.

c# datagridview gridlines

I have a gridview that I wish to display gridlines only on certain rows.
I want them to be on each column, but only after every 4 rows. Is this possible?
Thanks.
You can use the DataGridView.CellPainting event.
You can always user javascript (JQuery) to select wanted columns on table generated by gridview asp.net. After selecting this columns, set their right-border to wanted value or color.
If you don't want to use javascript, you can use RowDataBound eventHandler. If your columns are template fields, you can find wanted control ( e.Row.FindControl("ControlName")) and it's parent ( e.Row.FindControl("ControlName").Parent ). I am not sure, but I think that parent should be wanted cell and then you can set borders. You can try something like this, I haven't tried this.

Categories

Resources