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
For IntColumn as Integer =0 to 4 --max 5 columns.
GotTo FILLValue
End if
Next
datagrid.Items.Add(New Button)
Next
FILLValue :
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 ??
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 2For 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 ThenGotTo 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 ??