As the subject says I want to insert an image into the 2nd column of grid
defined with 2 columndefintions.
Programmatically that is???
I cannot see how to select the column using grid.Children.insert(1, img)
does not work.
Malcolm
Image imgControl = new Image();
Grid.SetColumn(imgControl, 1);
gridContainer.Children.Add(imgControl);
Objects contained in a grid are positioned based on the attached dependency properties Column Row ColumnSpan and RowSpan which are set as shown above.
The row/column index on an element in WPF is an attached property. You set it using a static method on Grid, like this:
Grid.SetColumn(img, 1);
More info here, and more about attached properties here.
Related
I have a DataGrid that is populated in Codebehind using its DataContext. So the columns are auto generated and the actual number of columns generated do change.
Ultimately I need to be able to display a barchart in the Cells (col) depending on the value of a cell in another field (Col + 1).
My initial thoughts are to add a rectangle and change its width to the percentage of the cell width based on the value in col + 1 - but I am failing to find where to start doing this entirely in code behind.
Has anyone done this or have any advice that might help me get to what I am looking for please?
I can give more information if required.
EDIT:
As Requested, I thought I would try and visualize what I am after better. So, my Datagrid is populated with data similar to the following:
where there are 3 sets of 2 columns (a Perc & Result column for 1, 2 & 3... This number could be up to anything!). Now, the value in the Perc column is referenced to conditionally control the style of rectangles that sit in the respective Result columns (in this example I am using colours to represent the percent. In reality I am looking to use the perc value to set the width of the coloured rectangle in the Datagrid cell to give a barchart appearance).
Finally, I will hide all the Perc columns so the results will look like:
Does that mke any more sense... I hope I havent confused things further??
I am using the synfusion GridControl in my application.The user can select a text file and data from the file is displayed in the grid. Each and every time the grid is populated the column width is set using the code.
_gridPDD.ColWidths.SetSize(i, columnWidth);
where columnWidth will hold some fixed value based on the type of data displayed in the column.
Now the below test case works differently-
The user changes the width of the columns in the grid by dragging the edge of columns. When a new file is opened in the application and the grid is populated the columns are not shown with the default width (width set with the above line of code) instead they are set with the width of the columns in the previous section ( The width of column after the user perform a drag ).
Any help in this... Is there any property in the syncfusion GridControl that makes this behaviour? How to avoid this behaviour?
Thank you for your interest in Syncfusion products.
Your problem is the size(the width of column after the user perform a drag ) getting modified. In order to resolve this please restrict the resizing option using ResizeColsBehaviour. You may be resizing(by dragging the columns) to view the data. For that you can use AllowPropotionalColumnSizing. This allows you to resize the columns proportionately as per the data size.
Code Snippet:
//to restrict the resizing option using drag
this.grid.Model.Options.ResizeColsBehavior = GridResizeCellsBehavior.None;
//to resize the columnpropotionatelt according to the column data
this.grid.AllowProportionalColumnSizing = true;
Reference :
http://www.syncfusion.com/kb/695/how-to-prevent-column-resizing-for-child-tables-in-gridgroupingcontrol
http://www.syncfusion.com/kb/4853/how-to-optimize-the-resizetofit-method-for-large-number-of-records
Please let us know if your requirement is different from this.
Thanks & Regards,
AL.Solai.
I have a listview (details view) and I display a column of images and a column of text,
It's possible to display the image in the second column (without OwnerDraw)? I want to put the text in the first because only the first column can be edited by the user (LabelEdit property)
ListViewItem lvi = new ListViewItem("");
lvi.ImageKey = "image"; // column 1
lvi.SubItems.Add("subitem 2"); // column 2
Thank You
UPDATE
Native listview supports images in subitems (LVS_EX_SUBITEMIMAGES) since before win 98 but they didn't include it in .NET.
http://msdn.microsoft.com/en-us/library/windows/desktop/bb774732(v=vs.85).aspx
A codeproject example
http://www.codeproject.com/Articles/7630/ListView-with-Image-on-SubItems
No, without OwnerDraw it is not possible.
In your case the simplest thing is to manage the editing of other columns instead of manage the OwnerDraw. There are some example of how to do it:
example 1
example 2
example 3
ecc...
After constructing a Grid and adding Rows and Columns to it, how can modify the dimension of each Cell. I am not able to locate any property that would help me to achieve this.
As additional note, I am adding TextBlocks to each of the cell.
You can change the column width and row height within your ColumnDefinition and RowDefinition tags, or if you wish to have the cells in a less uniform arrangement you can set the ColumnSpan (might be ColSpan, it's been a while!) and RowSpan properties of each cell to create cells that span more than one row or column.
Do you want modify cells dimensions at runtime? If yes take a look at GridSplitter.
I create some control in codebehind and would like to set its size dynamically.
I can assign numerical values as well as System.Windows.GridLength.Auto, but there is no equivalent to "*".
Is that because the "*" from XAML gets translated into code when the WPF gets parsed?
To give this some detail: There is a grid with three rows. I want the top and bottom row to take all the space they can, while the middle row remains auto-sized.
var gridLength = new GridLength(1, GridUnitType.Star);
More info.