how to find footer's value of gridview on RowCommand event? - vb.net

I want to find footer's value on the event of RowCommand in vb.net??
I'm assigning footer's value run-time on RowCreated.
e.Row.Cells(2).Text = FOOTERVALUE
e.Row.Cells(1).Text = "Total Subjects"
And this footer is for Parent Grid. I'm using nested gridview.

Protected Sub Gridview1RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles Gridview1.RowCommand
Dim Lblcolval = CType(dgrd_WWWH.FooterRow.FindControl("yourcolumn") ,Label)
End Sub
Protected Sub Gridview1_How_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
If e.Row.RowType And DataControlRowType.Footer Or (e.Row.RowState And DataControlRowState.Edit) > 0 Then
Dim ddlresp As DropDownList = CType(e.Row.FindControl("ddlResp"), DropDownList)
SrchWhoBind(ddlresp)
ddlresp.SelectedValue = Convert.ToInt32(Session("Uname"))
End If
End Sub

I got the solution, just needed to write the code in rowDataBound instead of rowCreated.

Related

How to Transfer Datagrid Value of one form to TextBoxes of another form?

I cant somehow figure why it can't transfer the data with no errors
Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim pinfo As New Employee_Personal_Info()
pinfo.ShowDialog()
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
Employee_Personal_Info.TextBox1.Text = row.Cells("emp_firstname").Value.ToString
End If
End Sub
Apart from the fact that you're displaying the form before passing it the data, the issue is that you are setting the Text of a TextBox on the default instance of that form, not the instance you created. This:
Employee_Personal_Info.TextBox1.Text = row.Cells("emp_firstname").Value.ToString
should be this:
pinfo.TextBox1.Text = row.Cells("emp_firstname").Value.ToString
you can pass via globle variable like
public text as string
Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
text=row.Cells("emp_firstname").Value.ToString
End Sub

Get Selected row item from gridview2

I have a one gridcontrol (GridControl1)
Inside thid gridcontrol, there is two Grid Views (GridView1 & GridView2)
I want to get value of Selected row item in GridView2 and put it in a textbox.
on GridView1 I Can Get That using This Code:
txtEmpId.Text = GridView1.GetFocusedRowCellDisplayText(colEmp_Id)
But if I Select any Row on GridView2, nothing I will get.
Is there any method to do that.
If you have using the master-detail please review the help article describing in detail
In you GridControl you must handle the Grid_MasterRowExpanded and then add programmaticuly a handle to gridView.SelectionChanged ,this code will help you
Private Sub Grid_MasterRowExpanded(ByVal sender As System.Object, ByVal e As DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs) Handles Grid.MasterRowExpanded
Dim view As GridView = sender
Dim detail As GridView = view.GetDetailView(e.RowHandle, e.RelationIndex)
detail.OptionsSelection.MultiSelect = True
If e.RowHandle = 0 Or e.RowHandle = 1 Then
AddHandler detail.SelectionChanged, AddressOf detail_SelectionChanged
End If
End Sub
Private Sub detail_SelectionChanged(ByVal sender As System.Object, ByVal e As DevExpress.Data.SelectionChangedEventArgs)
viewSelected = sender
Dim ro As DataRowView = viewSelected.GetFocusedRow
txtEmpId.Text = ro.Item("colEmp_Id")
End Sub

Trigger an event with one sub for multiple controls

I have 10 panels on my form, and when you hover them, their color changes. I have 10 private subs like so...
Private Sub pnl2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnl2.MouseHover
pnl2.BackColor = Color.WhiteSmoke
End Sub
This code is repeated for each panel with the only difference being it's name, how can I do this more efficiently? as it is very repetitive.
Add them at the handler statement appending each by a comma. The sender object is the panel in question so cast it to change it's properties.
Private Sub pnl2_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles pnl2.MouseHover, pnl3.MouseHover 'etc
Dim pnl As Panel = CType(sender, Panel)
pnl.BackColor = Color.WhiteSmoke
End Sub

Datagridview combobox column's value

I have a datagridview combo box with a few values in there. I am trying to capture what user clicked. I tried CellValueChanged, CellContentClicked etc. but nothing works.
I want to store this value to a variable (important) and then shift the cursor to column after user has selected value.
Please help. Please also advise what event to fire.
Thanks
Private Sub dg_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dg.CellValueChanged
If flgLD = 1 Then
Dim retreivedValue As Object = dg.Rows(dg.CurrentRow.Index).Cells(0).Value
dg.Rows(dg.CurrentRow.Index).Cells(1).Value = retreivedValue
dg.CurrentCell = dg.Rows(dg.CurrentRow.Index).Cells(1)
dg.BeginEdit(True)
End If
End Sub
Use CellValueChanged Event, then check what Column is chosen by the user, then you can retreive the value. Here an example:
Private Sub yourGrid_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles yourGrid.CellValueChanged
If e.ColumnIndex = yourComboColumn.Index Then
Dim retreivedValue As Object = yourGrid(e.ColumnIndex, e.RowIndex).Value
End If
End Sub

To get the commandargument in rowdatabound event in gridview

Following is code for buttonclick in gridview.
Protected Sub lnkChangeStatus_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim gvr As GridViewRow = TryCast(DirectCast(sender, LinkButton).Parent.Parent, GridViewRow)
Dim lngProfileId As Long = Convert.ToInt64(gvwBusinessProfiles.DataKeys(gvr.RowIndex).Value)
End Sub
I want to get commandargument of lnkChangeStatus in its click.Is there any way
I guess the syntax for the eventhandler (Command event as against Click) should be as below.
Protected Sub lnkChangeStatus_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
.....
End Sub
You can use e.CommandName or e.CommandArgument inside the code block.
Refer this