I have created Xtragrid in which i have added RepositoryItemLookUpEdit at run time but the problem is when i add a new row by using View.AddNewRow(); a new row is added with empty cell. So i need to add RepositoryItemLookUpEdit in new created row. Can any body help me ?
I had the same issue. You need to use a datasource that implements IBindingList, such as BindingList and also set AllowNew = true
Where do you bind the data?
Can I suggest you implement the following ex and see where the problem starts?
Start with a grid and button on the form. I created the repository item in the designer
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable("newTable");
dt.Columns.Add("1", typeof(Int32));
dt.Columns.Add("2", typeof(bool));
dt.Columns.Add("3", typeof(Int32));
dt.Rows.Add(1, true, 12);
dt.Rows.Add(2, false, 32);
dt.Rows.Add(3, true, 42);
gridControl1.DataSource = dt;
gridView1.Columns[0].ColumnEdit = repositoryItemCheckEdit1;
}
private void button1_Click(object sender, EventArgs e)
{
gridView1.AddNewRow();
}
It adds a new row with a repository item in the 1st column :)
I always add one more item in data source, for example:
private void AgregarDetalle_Click(object sender, EventArgs e) {
var list = GridOpcionDetalle.DataSource as List<DetalleOpcion>;
list.Add(new DetalleOpcion());
GridOpcionDetalle.DataSource = list;
GridOpcionDetalle.RefreshDataSource();
}
Private Sub grdInvoice_EditorKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grdInvoice.EditorKeyDown
Dim dt As New DataTable
Dim dr As DataRow
Dim i As Integer
With GridView1
.OptionsNavigation.EnterMoveNextColumn = True
If e.KeyData = "13" Or e.KeyData = "9" Then
If .FocusedRowHandle.ToString = .RowCount - 1 Then
If .FocusedColumn Is .Columns("Rate") Then
If .GetRowCellValue(.RowCount - 1, "Qty") <> "0" And .GetRowCellValue(.RowCount - 1, "Rate") <> "0" And .GetRowCellValue(.RowCount - 1, "ItemCode") <> "" Then
dt.Columns.Add("No")
dt.Columns.Add("ItemCode")
dt.Columns.Add("ItemName")
dt.Columns.Add("Qty")
dt.Columns.Add("Rate")
dt.Columns.Add("Amount")
dt.Columns.Add("Unit")
For i = 0 To .RowCount - 1
dr = dt.NewRow
dr("No") = .GetRowCellValue(i, "No")
dr("ItemCode") = .GetRowCellValue(i, "ItemCode")
dr("ItemName") = .GetRowCellValue(i, "ItemName")
dr("Rate") = .GetRowCellValue(i, "Rate")
dr("Qty") = .GetRowCellValue(i, "Qty")
dr("Amount") = .GetRowCellValue(i, "Amount")
dr("Unit") = .GetRowCellValue(i, "Unit")
dt.Rows.Add(dr)
Next
dr = dt.NewRow
dr("No") = .GetRowCellValue(i - 1, "No") + 1
dr("ItemCode") = ""
dr("ItemName") = ""
dr("Rate") = "0"
dr("Qty") = "0"
dr("Amount") = "0"
dr("Unit") = ""
dt.Rows.Add(dr)
grdInvoice.DataSource = dt
.FocusedRowHandle = i
.FocusedColumn = .Columns("ItemCode")
End If
End If
End If
End If
End With
Related
I have created a dynamic table in my code behind which loads up on page load. I have created a button which when clicked I need to add a <div> to specific <td> in the table. However, it is not finding my <td> element using the id. What am I doing wrong?
Function CalendarRefresh(Day As Integer, MonthDays As Integer)
Dim iDay As Integer = 1
Dim TableID As Integer
Dim TDCount As Integer = 0
Dim FullTDCount As Integer = 0 '42
Dim StringHtml As New StringBuilder
Dim DaysInMonth As Integer = MonthDays
clsWork.GetUnscheduledWork()
Dim ClientName = "Terence Creighton" ' Test Replace with DB Value
Dim JobName = "Install Job"
' Top structure of table
StringHtml.Append("<table id='calendar' runatserver='server'>")
StringHtml.Append("<tr class='weekdays'>")
StringHtml.Append("<th scope='col'>Sunday</th>")
StringHtml.Append("<th scope='col'>Monday</th>")
StringHtml.Append("<th scope='col'>Tuesday</th>")
StringHtml.Append("<th scope='col'>Wednesday</th>")
StringHtml.Append("<th scope='col'>Thursday</th>")
StringHtml.Append("<th scope='col'>Friday</th>")
StringHtml.Append("<th scope='col'>Saturday</th>")
StringHtml.Append("</tr>")
StringHtml.Append("<tr Class='days'>")
If Day > 1 Then
Do While iDay < (Day)
' add Previous month style
StringHtml.Append("<td class='day other-month'>")
StringHtml.Append("</td>")
iDay = iDay + 1
TDCount = TDCount + 1
FullTDCount = FullTDCount + 1
Loop
End If
For i As Integer = 1 To DaysInMonth
If TDCount = 7 Then
StringHtml.Append("</tr>")
StringHtml.Append("<tr class='days'>")
TDCount = 0
FullTDCount = FullTDCount + 1
i = i - 1
Else
StringHtml.Append("<td class='day' ")
StringHtml.Append("id='")
StringHtml.Append(i)
StringHtml.Append("' Runat='server'>")
StringHtml.Append("<div class='date'>")
StringHtml.Append(i)
StringHtml.Append("</div>")
'StringHtml.Append("<div id='")
'StringHtml.Append(i)
'StringHtml.Append("' Runat='server'>")
'StringHtml.Append("<div Class='panel panel-primary' draggable='true'>")
'StringHtml.Append("<div Class='panel-heading'>")
'StringHtml.Append(ClientName)
'StringHtml.Append("</div>")
'StringHtml.Append("<div Class='panel-body'>")
'StringHtml.Append(JobName)
'StringHtml.Append("</div>")
'StringHtml.Append("</div>")
StringHtml.Append("</div>")
StringHtml.Append("</td>")
TDCount = TDCount + 1
FullTDCount = FullTDCount + 1
End If
Next
StringHtml.Append("</tr>")
StringHtml.Append("</table>")
Return StringHtml.ToString
End Function
Public Sub ScheduledJobs()
Dim StringHtml As New StringBuilder
Dim ClientName As String
Dim JobName As String
Dim Work = clsWork.GetUnscheduledWork()
For Each i As Integer In Work.Rows.Count
ClientName = Work.Rows(i).Items("ClientName").ToString
JobName = Work.Rows(i).Items("JobName").ToString
ID = i.ToString
StringHtml.Append("<div class='panel panel-primary' draggable='true' ondragstart='OnDragStart' ondrop='OnDrop' ")
StringHtml.Append("id='")
StringHtml.Append(ID)
StringHtml.Append("'>")
StringHtml.Append("<div class='panel-heading'>")
StringHtml.Append(ClientName)
StringHtml.Append("</div>")
StringHtml.Append("<div class='panel-body'>")
StringHtml.Append(JobName)
StringHtml.Append("</div>")
Next
Dim MyTable As HtmlTable = Page.FindControl("calendar")
Dim MyCell As HtmlTableCell
MyCell.ID = "19"
If MyCell Is Nothing Then
messageResponse = "Tablecell not found"
Else
MyCell.InnerHtml = StringHtml.ToString
End If
End Sub
Private Sub cmdLoadJobs_ServerClick(sender As Object, e As EventArgs) Handles cmdTry.ServerClick
ScheduledJobs()
End Sub
I am expecting find the td with the ID and add the html string in the ("td Element").innerhtml. I have tried various combinations of findcontrol but all turns up empty
You have to create real dynamic controls. Here a very basic example of how to interact with a dynamically created table.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
//do not create dynamic control in an ispostback check
}
//create some table and it's rows and cells. note the assignent of an ID
Table table = new Table()
{
ID = "MyTable1"
};
TableRow row = new TableRow()
{
ID = "MyRow1"
};
TableCell cell = new TableCell()
{
ID = "MyCell1",
Text = "My 1st cell"
};
//add the cell to the row
row.Controls.Add(cell);
//add the row to the table
table.Controls.Add(row);
//add the table to the page
PlaceHolder1.Controls.Add(table);
}
protected void Button1_Click(object sender, EventArgs e)
{
//use findcontrol to locate the cell
TableCell cell = PlaceHolder1.FindControl("MyCell1") as TableCell;
//interact with it
cell.Text = "Cell Found!";
}
I see this:
StringHtml.Append("<table id='calendar' runatserver='server'>")
While it's certainly fine to push raw html to a page in the browser by building an html string, you cannot create server controls this way. You won't be able to access anything in that html from your code behind. The runat='server' part is first of all keyed wrong, but would be worthless even if written correctly. By the time you're in the Page_Load event, everything that looks for the runat='server' attribute has already finished.
Hello I am trying to get this Pager working. I am having some trouble adding the event handler to pagerCommand event. What am i doing wrong? I can attach the handler to the dropdown with no problem, but the link is having an issue. Any guidance will be appreciated. Thanks
Public Class DataPagerDDL
Inherits DataPager
Protected Overrides Sub OnInit(ByVal e As EventArgs)
Me.CreateDefaultPagerFields()
MyBase.OnInit(e)
End Sub
Protected Sub CreateDefaultPagerFields()
'add custom template
Dim templateField As TemplatePagerField = New TemplatePagerField
templateField.PagerTemplate = New CustomTemplate
'add previous/next page template
Fields.Add(templateField)
End Sub
Public Sub cmbPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim cmbPage As DropDownList = CType(sender, DropDownList)
SetPageProperties((cmbPage.SelectedIndex * MaximumRows), MaximumRows, True)
End Sub
Public Sub cmb_PagerCommand(ByVal sender As Object, ByVal e As DataPagerCommandEventArgs)
' Check which button raised the event
Select Case e.CommandName
Case "Next"
Dim newIndex As Integer = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize
If newIndex <= e.TotalRowCount Then
e.NewStartRowIndex = newIndex
e.NewMaximumRows = e.Item.Pager.MaximumRows
End If
Case "Previous"
e.NewStartRowIndex = e.Item.Pager.StartRowIndex - e.Item.Pager.PageSize
e.NewMaximumRows = e.Item.Pager.MaximumRows
Case "First"
e.NewStartRowIndex = 0
e.NewMaximumRows = e.Item.Pager.MaximumRows
Case "Last"
Dim newIndex As Integer = e.Item.Pager.StartRowIndex + e.Item.Pager.PageSize
If newIndex <= e.TotalRowCount Then
e.NewStartRowIndex = newIndex
e.NewMaximumRows = e.Item.Pager.MaximumRows
End If
End Select
End Sub
End Class
Public Class CustomTemplate
Implements System.Web.UI.ITemplate
Dim PageCount As Integer
Dim CurrentPage As Integer
Dim PageSize As Integer
Dim TotalRowCount As Integer
Dim MaximumRows As Integer
Dim StartRowIndex As Integer
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim caller As DataPagerFieldItem = CType(container, DataPagerFieldItem)
Dim pager As DataPagerDDL = CType(caller.Parent, DataPagerDDL)
PageSize = pager.PageSize
TotalRowCount = pager.TotalRowCount
MaximumRows = pager.MaximumRows
PageCount = (TotalRowCount / MaximumRows)
If ((pager.TotalRowCount Mod pager.MaximumRows) > 0) Then
PageCount = (PageCount + 1)
End If
Dim link As LinkButton = New LinkButton
'first Link
link.Text = "<< First "
link.CommandName = "Page"
link.CommandArgument = "First"
link.ID = "lnkFirst"
link.Enabled = StartRowIndex > 0
container.Controls.Add(link)
'prev link
link = New LinkButton
link.Text = "< Prev "
link.CommandName = "Page"
link.CommandArgument = "Previous"
link.ID = "lnkPrev"
link.Enabled = StartRowIndex > 0
container.Controls.Add(link)
CurrentPage = ((StartRowIndex / MaximumRows) + 1)
Dim cmbPage As DropDownList = New DropDownList
cmbPage.ID = "cmbPage"
cmbPage.AutoPostBack = True
Dim i As Integer = 1
Do While (i <= PageCount)
Dim item As ListItem = New ListItem(i.ToString, i.ToString)
If (i = CurrentPage) Then
item.Selected = True
End If
cmbPage.Items.Add(item)
i = (i + 1)
Loop
AddHandler cmbPage.SelectedIndexChanged, AddressOf pager.cmbPage_SelectedIndexChanged
'add nav buttons
' we just add a Label with 'Page ' Text
container.Controls.Add(PageOf())
' our DropDownList control here.
container.Controls.Add(cmbPage)
' and our Total number of Pages
container.Controls.Add(PageTotal())
'next link
link = New LinkButton
link.Text = "Next > "
link.CommandName = "Page"
link.CommandArgument = "Next"
link.ID = "lnkNext"
link.Enabled = StartRowIndex + PageSize < TotalRowCount
container.Controls.Add(link)
'last link
link = New LinkButton
link.Text = "Last >> "
link.CommandName = "Page"
link.CommandArgument = "Last"
link.ID = "lnkLast"
link.Enabled = StartRowIndex + PageSize < TotalRowCount
'Problem line
AddHandler pager.cmb_PagerCommand, New EventHandler(AddressOf pager.cmb_PagerCommand)
container.Controls.Add(link)
container.Controls.Add(PageInfo(TotalRowCount))
End Sub
Private Function PageOf() As Label
' it is just a label
Dim lbl As New Label()
lbl.Text = " Page "
Return lbl
End Function
Private Function PageTotal() As Label
' a label of GridView's Page Count
Dim lbl As New Label()
lbl.Text = String.Format(" of {0} ", PageCount)
Return lbl
End Function
Private Function PageInfo(ByVal rowCount As Integer) As Label
' create a label that will display the current Record you're in
Dim label As New Label()
Dim currentPageFirstRow As Integer = ((CurrentPage * PageSize) + 1)
Dim currentPageLastRow As Integer = 0
Dim lastPageRemainder As Integer = rowCount Mod PageSize
currentPageLastRow = IIf((PageCount = CurrentPage + 1), (currentPageFirstRow + lastPageRemainder - 1), (currentPageFirstRow + PageSize - 1))
label.Text = [String].Format("Record {0} to {1} of {2}", currentPageFirstRow, currentPageLastRow, rowCount)
Return label
End Function
End Class
DataPager.png
This is what I have for my gridview, I am trying to replicate the functionality in a free standing pager. A little stumped at the moment
Try replacing the following line of code
AddHandler pager.cmb_PagerCommand, New EventHandler(AddressOf pager.cmb_PagerCommand)
with
AddHandler link.Command, AddressOf pager.cmb_PagerCommand
I have added Checkbox and Radio buttons as column values to the GridView in runtime.
Now, i am unable to fire Checkbox_CheckedChanged event upon Checkbox.checked
Any suggestions on how to call event ? Below is the Grid i implemented.
Below is the source code:
1) Grid Init
Dim COUNT As Integer = 0
For i As Integer = 0 To ListHeaderDataFieldArray.Count - 1
If ListHeaderDataFieldArray(i) = Me.CRMSignCond Then
Dim TemplateCol As New TemplateField
TemplateCol.ItemStyle.HorizontalAlign = HorizontalAlign.Center
TemplateCol.ItemStyle.Width = New Unit(RowChildWidth)
TemplateCol.HeaderText = ListHeaderTextArray(i)
TemplateCol.ItemTemplate = New GridViewTemplate(DataControlRowType.DataRow, ListHeaderDataFieldArray(i))
GridviewChild.Columns.Add(TemplateCol)
Else
If ListHeaderTextArray(i) = "Target Sign" Then
Dim colItem As TemplateField = New TemplateField
colItem.HeaderText = ListHeaderTextArray(i)
'colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
ElseIf ListHeaderTextArray(i) = "Consolidate" Then
Dim colItem As TemplateField = New TemplateField
colItem.HeaderText = ListHeaderTextArray(i)
'colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
ElseIf ListHeaderTextArray(i) = "Signing Group" Then
Dim colItem As TemplateField = New TemplateField
colItem.HeaderText = ListHeaderTextArray(i)
'colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
Else
Dim colItem As BoundField = New BoundField
colItem.HeaderText = ListHeaderTextArray(i)
colItem.DataField = ListHeaderDataFieldArray(i)
colItem.SortExpression = ListHeaderDataFieldArray(i)
colItem.ItemStyle.Width = New Unit(RowChildWidth)
GridviewChild.Columns.Add(colItem)
End If
End If
2) Adding Controls to the GridView Columns in "RowDataBound" event.
Protected Sub GridviewChild_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridviewChild.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow AndAlso Not String.IsNullOrEmpty(CRMSignCond) Then
Dim s As String = ""
Dim lbValue As Label = DirectCast(e.Row.Cells(5).FindControl("lbValue"), Label)
e.Row.Cells(5).Attributes.Add("onmousemove", "Show('" + lbValue.Text + "')")
e.Row.Cells(5).Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor;Hide();")
End If
Dim cbTargetSign As New CheckBox
Dim rbConsolidate As New RadioButton
Dim tbSignGrp As New TextBox
cbTargetSign.ID = "chkSelect"
cbTargetSign.AutoPostBack = True
rbConsolidate.ID = "rbConsolidate"
tbSignGrp.ID = "tbConsolidate"
tbSignGrp.Width = 25
If Not e.Row.RowIndex = -1 Then
e.Row.Cells(6).Controls.Add(cbTargetSign)
e.Row.Cells(4).Controls.Add(tbSignGrp)
For i As Integer = 0 To 1
rbConsolidate = New RadioButton()
If i = 0 Then
rbConsolidate.Text = "YES"
Else
rbConsolidate.Text = "NO"
End If
'ii.Location = New Point(20, tt)
'ii.Tag = fileArray(i)
'tt = tt + 20
rbConsolidate.GroupName = "Consolidate"
e.Row.Cells(7).Controls.Add(rbConsolidate)
Next
End If
End Sub
Regards,
VK
You are adding and binding events programmatically in code behind and adding them to the GridView. And since dynamic Controls need to be recreated on every time the page is loaded to function properly, you should make sure the RowDataBound event is triggered on every Page Load, and that includes a PostBack.
So I'm guessing you do this (like you would normally):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
GridView1.DataSource = mySource
GridView1.DataBind
End If
End Sub
Change it to
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
GridView1.DataSource = mySource
GridView1.DataBind
End Sub
I'm using Devexpress Xtragrid TileView module.
Basically I want my code works like this :
user input member ID on the upper left textbox and press load.
If they exists, then a Tile will be appeared.
A tile should contain : Name, Status, member ID and a photo.
If user press load again (either same ID or another ID) a Tile will be added also, and so on. Unless they press Clear & Load, It should be only 1 latest tile left.
So, I'm able to produce up to Step 3.
But I couldn't be able to load the picture.
The picture itself, It's not a byte array. It's a Image path.
e.q : D:/test/1.jpg
So, how do I load the picture?
Protected Overridable Sub InitData()
Try
Dim homesTable = ds.Tables(0)
homesTable.Columns.Add("ImageCol")
For Each row_Renamed As DataRow In homesTable.Rows
Dim img As Image = Image.FromFile(row_Renamed("memberPhoto")) 'I tried this, but didn't work
row_Renamed("ImageCol") = img
Next row_Renamed
GridControl1.DataSource = homesTable
Catch
End Try
End Sub
Private Sub setupTile()
'For i = 0 To j - 1
Try
TileView1.BeginUpdate()
'TileView1.DataSource = ds.Tables(0)
TileView1.OptionsTiles.RowCount = 3
TileView1.OptionsTiles.Padding = New Padding(20)
TileView1.OptionsTiles.ItemPadding = New Padding(10)
TileView1.OptionsTiles.IndentBetweenItems = 20
TileView1.OptionsTiles.ItemSize = New Size(320, 170)
TileView1.Appearance.ItemNormal.ForeColor = Color.White
TileView1.Appearance.ItemNormal.BorderColor = Color.Transparent
'Setup tiles template
Dim leftPanel As New TileViewItemElement()
Dim splitLine As New TileViewItemElement()
Dim nameCaption As New TileViewItemElement()
Dim nameValue As New TileViewItemElement()
Dim statusCaption As New TileViewItemElement()
Dim statusValue As New TileViewItemElement()
Dim RGPCaption As New TileViewItemElement()
Dim RGPvalue As New TileViewItemElement()
Dim imageTile As New TileViewItemElement()
TileView1.TileTemplate.Add(leftPanel)
TileView1.TileTemplate.Add(splitLine)
TileView1.TileTemplate.Add(nameCaption)
TileView1.TileTemplate.Add(nameValue)
TileView1.TileTemplate.Add(statusCaption)
TileView1.TileTemplate.Add(statusValue)
TileView1.TileTemplate.Add(RGPCaption)
TileView1.TileTemplate.Add(RGPvalue)
TileView1.TileTemplate.Add(imageTile)
'
'nameValue.Text = ""
'statusValue.Text = ""
'RGPvalue.Text = ""
'imageTile.Image = Nothing
'
leftPanel.StretchVertical = True
leftPanel.Width = 190
leftPanel.TextLocation = New Point(-10, 0)
leftPanel.Appearance.Normal.BackColor = Color.FromArgb(58, 166, 101)
'
splitLine.StretchVertical = True
splitLine.Width = 3
splitLine.TextAlignment = TileItemContentAlignment.Manual
splitLine.TextLocation = New Point(190, 0)
splitLine.Appearance.Normal.BackColor = Color.White
'
nameCaption.Text = "Name"
nameCaption.TextAlignment = TileItemContentAlignment.TopLeft
nameCaption.Appearance.Normal.FontSizeDelta = -1
'
nameValue.Column = TileView1.Columns("preferredName")
nameValue.AnchorElement = nameCaption
nameValue.AnchorIndent = 2
nameValue.MaxWidth = 200
nameValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'nameValue.Text = ds.Tables(0).Rows(i)("preferredName").ToString
'
statusCaption.Text = "Status"
statusCaption.AnchorElement = nameValue
statusCaption.AnchorIndent = 14
statusCaption.Appearance.Normal.FontSizeDelta = -1
'
statusValue.Column = TileView1.Columns("memberStatus")
statusValue.AnchorElement = statusCaption
statusValue.AnchorIndent = 2
statusValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'statusValue.Text = ds.Tables(0).Rows(i)("memberStatus").ToString
'
RGPCaption.Text = "RGP"
RGPCaption.AnchorElement = nameValue
RGPCaption.AnchorIndent = 65
'RGPCaption.TextLocation
'RGPCaption.Appearance.Normal.FontSizeDelta = -1
RGPCaption.Appearance.Normal.Font = New Font("Segoe UI Semibold", 12.0F, System.Drawing.FontStyle.Regular)
'
RGPvalue.Column = TileView1.Columns("code")
RGPvalue.AnchorElement = RGPCaption
RGPvalue.AnchorIndent = 1
RGPvalue.TextAlignment = TileItemContentAlignment.BottomLeft
RGPvalue.Appearance.Normal.Font = New Font("Segoe UI Semilight", 25.75F, System.Drawing.FontStyle.Regular)
'RGPvalue.Text = ds.Tables(0).Rows(i)("code").ToString
'
imageTile.Column = TileView1.Columns("ImageCol")
imageTile.ImageSize = New Size(120, 170)
imageTile.ImageAlignment = TileItemContentAlignment.MiddleRight
imageTile.ImageScaleMode = TileItemImageScaleMode.Stretch
imageTile.ImageLocation = New Point(12, 0)
Catch ex As Exception
XtraMessageBox.Show(ex.Message)
Finally
TileView1.EndUpdate()
End Try
'Next
End Sub
Private Sub loadBtn_Click(sender As Object, e As EventArgs) Handles loadBtn.Click
initData()
setupTile()
End Sub
Maybe it's too late but in my case only need to read file from disk and assign to a byte() column.
First of all, table column should be byte array so replace:
homesTable.Columns.Add("ImageCol")
for:
homesTable.Columns.Add(New DataColumn("ImageCol", GetType(Byte)))
Then I'd try to replace:
row_Renamed("ImageCol") = img
for:
row_Renamed("ImageCol") = IO.File.ReadAllBytes(row_Renamed("memberPhoto"))
That would load disk file to byte array and shown in tile. I'd check if file exists to avoid exceptions.
That's what I do to load image from disk.
Hope it helps.
I'm trying to get the gridview details to be put into textboxes for better view and edit.
I'm listing the following code to create the gridview:
'Finds all cases that are not closed
Protected Sub listAllCases()
sqlCommand = New SqlClient.SqlCommand("SELECT TC.caseId,TS.subName,TSU.userName,TC.caseType,TC.caseRegBy,TC.caseTopic,TC.caseDesc,TC.caseSolu,TC.caseDtCreated, TC.caseStatus FROM TBL_CASE TC INNER JOIN TBL_SUBSIDIARY_USER TSU ON TC.caseUser = TSU.userID INNER JOIN TBL_SUBSIDIARY TS on TSU.usersubId = TS.subId WHERE TC.caseStatus = 0 order by caseId")
sqlCommand.Connection = sqlConnection
sqlConnection.Open()
'sqlCommand.Parameters.AddWithValue("#subID", Me.caseSub.SelectedItem.Value)
Dim dr As SqlClient.SqlDataReader
dr = sqlCommand.ExecuteReader
If dr.HasRows Then
allCases.DataSource = dr
allCases.DataBind()
Else
allCases.DataSource = Nothing
allCases.DataBind()
End If
dr.Close()
sqlConnection.Close()
End Sub
Then I use the a function on the gridview onselectindexchanged and Writes this:
Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs)
Dim row As GridViewRow = allCases.SelectedRow
txtcase.Text = row.Cells(1).Text()
txtsub.Text = row.Cells(2).Text
txtuser.Text = row.Cells(3).Text
oDato.Text = row.Cells(9).Text
lDato.Text = "Saken er ikke lukket!"
txttype.Text = row.Cells(4).Text.ToString
txtregBy.Text = row.Cells(5).Text.ToString
txttopic.Text = row.Cells(6).Text
txtDesc.Text = row.Cells(7).Text
txtSolu.Text = row.Cells(8).Text
lblinfo.Text = row.Cells(6).Text
End Sub
I only get it to display cells 1 to 9. Means cell 4 to 8 is not listed or being blank, even though i know it should contain data.
Any tips or Clues is very appreciated!
Like This ?
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As
TextBox1.text = DataGridView1.Rows(e.Index).Cells(0).value.toString
TextBox2.text = DataGridView1.Rows(e.Index).Cells(1).value.toString
TextBox3.text = DataGridView1.Rows(e.Index).Cells(2).value.toString
TextBox4.text = DataGridView1.Rows(e.Index).Cells(3).value.toString
TextBox5.text = DataGridView1.Rows(e.Index).Cells(4).value.toString
TextBox6.text = DataGridView1.Rows(e.Index).Cells(5).value.toString
TextBox7.text = DataGridView1.Rows(e.Index).Cells(6).value.toString
TextBox8.text = DataGridView1.Rows(e.Index).Cells(7).value.toString
TextBox9.text = DataGridView1.Rows(e.Index).Cells(8).value.toString
TextBox10.text = DataGridView1.Rows(e.Index).Cells(9).value.toString
End Sub
This will display all the information in the row by clicking the record...
e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
sorry for that ...
by clicking the data the (e.Index) will locate in which DataGridView.Rows(), then the cells.(n) and etc... will get your data
ok. i got it right, finally. the code i used to get it work is as follows:
Protected Sub allCases_OnSelectedIndexChanged(sender As Object, e As EventArgs)
Dim row As GridViewRow = allCases.SelectedRow
txtcase.Text = row.Cells(1).Text()
txtsub.Text = row.Cells(2).Text.ToString
txtuser.Text = row.Cells(3).Text
oDato.Text = row.Cells(9).Text
txtDesc.Text = TryCast(row.FindControl("lblcaseDesc"), Label).Text
txtSolu.Text = TryCast(row.FindControl("lblcaseSolu"), Label).Text
end sub
this means I need to fetch the boundfields and templatefields differently.
Anyhow thanks for the reponse.