This project has moved and is read-only. For the latest updates, please go here.

Dynamic Row and Button Column in Data Grid

Oct 29, 2014 at 2:12 PM
Edited Oct 29, 2014 at 2:19 PM
I want to create a datagrid with dynamic button column and row.
Each row might have maximum of 5 columns

let me tell my problem with an example
Input 7

1 2 3 4 5
6 7

if input is 2

1 2

if input is 11

1 2 3 4 5
6 7 8 9 10
11

data grid should be like this.
means in 1st case ,2 rows and 7 columns

in 2nd case,2 column with 1 row.

My code is for INPUT 7

for intRows as Integer 0 to 2
For IntColumn as Integer =0 to 4 --max 5 columns.
  Dim intValue as Integer
   intValue =(5*intRows  + IntColumn )+1

   Dim templatecol As New DataGridTemplateColumn()
    templatecol.Header = "Button Column"
    Dim factory As New FrameworkElementFactory(GetType(Button))
    factory.SetValue(Button.ContentProperty, intValue )
    factory.AddHandler(Button.ClickEvent, New RoutedEventHandler(Sub(s As Object, arg As              System.Windows.RoutedEventArgs)
                                                                     Dim win As New Window2()
                                                                     win.Show()
                                                                 End Sub))
    Dim cellTemplate As New DataTemplate()
    cellTemplate.VisualTree = factory
    templatecol.CellTemplate = cellTemplate
    datagrid.Columns.Add(templatecol)
if intValue =7 Then
GotTo FILLValue

End if

Next
datagrid.Items.Add(New Button)
Next

FILLValue :
     datagrid.Items.Add(New Button)
     datagrid.HeadersVisiblity=DataGridHeadersVisibilty.None

[
Code Image

http://postimg.org/image/w8egycnkr/4edd927c/

]

But now my buttons are like this

http://postimg.org/image/mcddyphsr/5c5ccaab/


How can i do that ??
Developer
Oct 30, 2014 at 9:31 PM
Hi,

From what I can see you are not using the Datagrid from the Extended WPF Toolkit. So I can not really help. Usually a grid is build to display column in 1 line. So I would say the behavior looks good. Columns aren't made to be positionned in multilines.