I want the code below in the event button to do string formatting in the datagridview column but there is a "row is not a member of eventargs" error. Is there something wrong with my code?.
Thanks
Dim result As Decimal = Nothing
If Decimal.TryParse(e.Row.Cells(4).Text, result) Then
e.Row.Cells(4).Text = String.Format("{0:#,##0.00}", result)
End If
Related
Can someone please help me fill my queried results into the existing datatable or a new datatable
''dt is filled with data from a csv file.
Dim dataRows As DataRow() = dt.Select("[Calendar year TEXT] = '2020'")
dt.Clear() 'Clear the datatable
dt.Rows.Add(dataRows) 'Add the result to the existing datatable or a new databletable if possible ?
So I've figured it out.
The reason I need a new DataTable is that I need to use it again in its original form later.
I could not attach the DataRow collection to my display control which is why I needed a new DataTable with the filtered results.
Private Function FilterDataTable(ByVal strQuery As String, ByVal dtRaw As DataTable)
Dim dataRows As DataRow() = dtRaw.Select(strQuery)
Dim dtFiltered As DataTable
dtFiltered = dtRaw.Clone() 'This is very important.
For Each drow As DataRow In dataRows
dtFiltered.ImportRow(drow) 'Add each filtered row to new DataTable.
Next
Return dtFiltered
End Function
Your dt.select will return an array of Datarow pointing to the rows in the datatable dt. Your dt.clear then clears the datatable and so will empty the dataRows array leaving you nothing left.
I'm not clear exactly what you are trying to do. I'm guessing you have a table that you want to filter and then discard all rows that don't match, leaving you a datatable to work with.
If so, here's a few options:
Work with the datarow array directly rather than the datatable. Is there really any need to convert the rows back to a datatable?
Create a new datatable to add the rows to, but don't clear the original table:
Dim dt As New DataTable ' Assume this is your populated table
Dim dataRows As DataRow() = dt.Select("[Calendar year TEXT] = '2020'")
Dim dtResults As DataTable = dt.Clone()
For Each row As DataRow In dr
dtResults.ImportRow(row)
Next
bare in mind any changes you make to the rows in dtResults will also affect the rows in dt as they both contain the same data
Depending on the size of your table and whether or not you really want to discard non matching rows, you could just remove all rows that don't match then work with the result:
Dim i As Integer = dt.Rows.Count - 1
While i >= 0
If dt(i).Item("Calendar") <> "Your test here" Then dt.Rows.Remove(dt(i))
i -= 1
End While
i have a problems regarding on filtering my code in retrieving companyName from its table..when i query here is the result .. please see my code
Sub call_customers(ByVal dgv_customers As DataGridView)
Dim customers_name = From cust In dbcon.Customers _
Select cust.CustomerID, cust.CompanyName Order By CompanyName Ascending
dgv_customers.DataSource = customers_name
End Sub
the display is CustomerID and CompanyName.. yeah its true.. no problem with the code..
and if i only select cust.companyname the result is this ....like this code
Sub call_customers(ByVal dgv_customers As DataGridView)
Dim customers_name = From cust In dbcon.Customers _
Select cust.CompanyName
dgv_customers.DataSource = customers_name
End Sub
the output is this...
enter image description here
no display and it says length.. why? newbie in LINQ sir ..
please help..
Originally, you were giving the grid an object, and it was displaying each of the properties of that object.
Now that you are giving it a string, it is doing the same thing, but now, the only property on the string is the length,
I would like to highlight a row from my RadGrid base on a logic row error (not database related).
I'm using Telerik Ajax .net RadGrid With VB.NET
If ok > 2000 Then
Dim errorRowOrderNumber = ok / 1000
'Get the RadGrid row error index
myErrorRow.Drawing.Color.Red
myErrorRow.Drawing.Color.White
End If
Use this if you can identify the error condition on item data bound event:
Protected Sub grid_ItemDataBound(sender As Object, e As GridItemEventArgs)
Try
If TypeOf e.Item Is GridDataItem Then
Dim dataRow = TryCast(e.Item, GridDataItem)
' Replace with validation logic
If True Then
dataRow.BackColor = Drawing.Color.Gray
dataRow.ForeColor = Drawing.Color.White
dataRow.ToolTip = "Some information about this error."
End If
End If
Catch ex As Exception
' handle exception
End Try
End Sub
In any other grid command event you can get a reference to the same GridDataItem object.
If you can't use a grid event try looking into client-side options.
Given an existing DataGrid called grid.
When I try to access grid.Columns("column_name") I get an exception
Column not found, column_name
I tried
If Not IsNull(grid.Columns("column_name")) Then '...
but I still get the exception.
I would like something which I could call like
grid.ContainsColumn("column_name")
The columns in a DataGrid only have a caption text to identify what the column is so you could use something like this to check if the column exists by looking for a column with a Caption that matches the column name you are looking for.
Private Function DataGrid_CheckColumnExists(dataGrid As dataGrid, columnName As String)
Dim columnCount As Long, columnIndex As Long
Dim checkColumnName As String
columnCount = dataGrid.Columns.Count
For columnIndex = 0 To columnCount - 1
checkColumnName = dataGrid.Columns(columnIndex).Caption
DataGrid_CheckColumnExists = (StrComp(checkColumnName, columnName, vbTextCompare) = 0)
If DataGrid_CheckColumnExists Then Exit Function 'No need to continue once we found it
Next columnIndex
End Function
I have been struggling with the below code snippet. "CustomUnboundColumnData" event is not firing.
Protected Sub gvAlertReport_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs)
If e.Column.FieldName = "Active" Then
Dim val As String = e.Value
Dim img As New ImageButton()
Select Case val
Case "False"
img.ImageUrl = "Images/gray_bell.png"
img.Attributes.Add("", "")
Case "True"
img.ImageUrl = "Images/red_bell.png"
img.Attributes.Add("", "")
Case Else
End Select
End If
End Sub
Thanks in Advance..
The CustomUnboundColumnData event is only triggered if there is a column in the ASPxGridView which is designed as an Unbound Column. To learn how this can be done, please refer to the Unbound Columns Overview topic. Also, please make certain that the gvAlertReport_CustomUnboundColumnData is the actual event handler for the ASPxGridView.