Is it possible to have a datagridview on a datarepeater contol and, if so, heave the datagridview bound or filtered on two fields in the datarepeator, one of them an integer (an id) and one of them a date?
Printable View
Is it possible to have a datagridview on a datarepeater contol and, if so, heave the datagridview bound or filtered on two fields in the datarepeator, one of them an integer (an id) and one of them a date?
Just about any control can be placed onto a DataRepeater but what is important is the design and flow of the data and controls.
A quick flow might go something like this (VS2008). Hopefully you can follow this code and get what you need for your project. My advice is always if possible learn how to use a control prior to using it in a project. Best to learn without the deadline of a project and do it at your own pace.
Load data, in this case from XML and setup databindings to two textboxes.
Code:Public Class Form_Vertical
Private CustomerView As New DataView
Also on the DrawItem event of the DataRepeater you can do additional work, in this case show an image based on a condition.Code:Private Sub LoadData()
Dim Customers = ( _
From customer In XDocument.Load("..\..\..\XML_Data\Customers.xml")...<Customer> _
Select Identifier = customer.<CustomerID>.Value, _
CompanyName = customer.<CompanyName>.Value, _
Address = customer.<Address>.Value, _
City = customer.<City>.Value, _
Country = customer.<Country>.Value).ToDataTable.AsDataView
txtIdentifer.DataBindings.Add(New Binding("Text", Customers, "Customers.Identifier"))
txtCompanyName.DataBindings.Add(New Binding("Text", Customers, "Customers.CompanyName"))
CustomerRepeater.DataSource = Customers
CustomerView = DirectCast(CustomerRepeater.DataSource, DataView)
CustomerView.Sort = "Identifier"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData()
End Sub
If you need to get data from the current rowCode:Private Sub CustomerRepeater_DrawItem(ByVal sender As Object, _
ByVal e As Microsoft.VisualBasic _
.PowerPacks.DataRepeaterItemEventArgs) _
Handles CustomerRepeater.DrawItem
If CustomerView.Count = 0 Then
Exit Sub
End If
Dim currItem As DataRowView = CustomerView(e.DataRepeaterItem.ItemIndex)
If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then
e.DataRepeaterItem.BackColor = Color.FromArgb(213, 224, 211)
Else
e.DataRepeaterItem.BackColor = SystemColors.Control
End If
If currItem("Country").ToString = "Germany" Then
DirectCast(e.DataRepeaterItem.Controls("PictureBox1"), PictureBox).Image = My.Resources.blue
Else
DirectCast(e.DataRepeaterItem.Controls("PictureBox1"), PictureBox).Image = My.Resources.green
End If
End Sub
Code:Private Sub cmdGetCurrent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetCurrent.Click
Dim CompanyName As String = CustomerRepeater.CurrentItem.Controls("txtCompanyName").Text
Dim Identifer As String = CustomerRepeater.CurrentItem.Controls("txtIdentifer").Text
MsgBox(String.Format("You are on the Company '{0}' Key '{1}'", CompanyName, Identifer))
End Sub
I watched the video they have on the download site. The datarepeater without the dgv seems pretty simple. My project uses table adapters and not a lot of code. My original idea was to use an MDI form with multiple instances of a child form and change the locations of these forms when the scroll bar is accessed by the user.
I hope I can get this to work.