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
Related
I created a registration form and added a form with features "Update, Delete, Refresh," along with a DataGridView to show data from the registration form.
Here's my form:
Since I inserted a TreeView, when I click the Update button as in the picture, I get the error:
Object Reference Not set to an instance of an object
I think my code in the TreeView form is wrong.
This is what I entered:
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If e.Node.Text = "Update/Delete Student" Then
Dim regstu As New Registered_Students
regstu.MdiParent = Me
regstu.Show()
End If
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If e.Node.Text = "Update/Delete Student" Then
Dim regstu As New Registered_Students
Form_father.IsMdiContainer = True
Form_father.TopLevel = False
regstu.MdiParent = New Form_father
Form_father.Panel1_Container.Controls.Add(regstu)
regstu.Show()
End If
End Sub
Here is my code, everytime I click the Button1, instead of refreshing the Datagridview, it only adds another entry that is a duplicate of the previous one. I know I'm missing something in my code that will clear the data in Datagrid before loading it again. Please help..
Private Function LoadData_UnitProcess()
Dim UP_SQL As String = "SELECT LotNum FROM Transactions WHERE StatusID=3 ORDER BY Process_EntryDate DESC"
Dim UP_Ad As OleDbDataAdapter = New OleDbDataAdapter(UP_SQL, strCon)
UP_Ad.Fill(UP_Ds, "Transactions")
UnitOnProcess_DG.DataSource = UP_Ds.Tables(0)
With UnitOnProcess_DG
.RowHeadersVisible = False
.Columns(0).HeaderCell.Value = "Lot #"
.Columns(0).Width = "363"
.AllowUserToAddRows = False
End With
LoadData_UnitProcess = ""
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LoadData_UnitProcess()
End Sub
Private Sub Displayer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData_UnitProcess()
End Sub
You dataset UP_Ds is probably a property or field. You need to reset the dataset before filling it again, otherwise the content is appended to the previous.
UP_Ds.Reset()
UP_Ad.Fill(UP_Ds, "Transactions")
UnitOnProcess_DG.DataSource = UP_Ds.Tables(0)
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.
I would like to know how to use the DataGridViewComboBoxEditingControl with vb.net
i need a routteen to run when the user select an item from the datagridviewcomboboxcolumn that i have configured. I am unsure how to attach the object to the column i create manually
I have implemented the following from examples on the internet but this only appears to trigger when the user click on the combobox within the column.
Private Sub dgvTicketDetail_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvTicketDetail.EditingControlShowing
Dim editingComboBox As ComboBox = TryCast(e.Control, ComboBox)
If editingComboBox IsNot Nothing Then
AddHandler editingComboBox.SelectedValueChanged, AddressOf EditingComboBox_DropDown
End If
End Sub
Private Sub EditingComboBox_DropDown(ByVal sender As System.Object, ByVal e As System.EventArgs)
Debug.WriteLine("A ComboBox in the DataGridView just dropped down.")
End Sub
any help would be appreciated as i cant seem to find much reference material for this
Thanks in advance
Just realised that i have never posted the answer to my question
Placed the following in the EditingControlShowing to capture request
Private Sub dgvTicketDetail_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvTicketDetail.EditingControlShowing
Try
If dgvTicketDetail.CurrentCell.ColumnIndex = 1 Then
Dim cmbox As ComboBox = TryCast(e.Control, ComboBox)
AddHandler cmbox.SelectionChangeCommitted, AddressOf Update_StockInfo
strSelectedText = cmbox.SelectedText
End If
Catch ex As Exception
End Try
End Sub
then this added items to the combobox cell
Private Sub Update_StockInfo(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim cmbClickedCell = DirectCast(sender, DataGridViewComboBoxEditingControl)
Dim cmbComboBox = DirectCast(sender, ComboBox)
If dgvTicketDetail.CurrentRow.Index = cmbClickedCell.EditingControlRowIndex And dgvTicketDetail.CurrentCell.ColumnIndex = 1 Then
Debug.WriteLine(cmbClickedCell.EditingControlRowIndex & cmbComboBox.SelectedValue)
Dim dtStock As DataTable = CropTrackMod.GetWeight(cmbComboBox.SelectedValue)
Dim dgvcc As DataGridViewComboBoxCell
dgvcc = dgvTicketDetail.Rows(cmbClickedCell.EditingControlRowIndex).Cells(2)
dgvcc.Items.Clear()
For Each row As DataRow In dtStock.Rows
dgvcc.Items.Add(row.Item("UnitName"))
Next row
If CropTrackMod.IsStockVATAble(cmbComboBox.SelectedValue) = True Then
dgvTicketDetail.Rows(cmbClickedCell.EditingControlRowIndex).Cells("VATRate").Value = CropTrackMod.dblVATRate
Else
dgvTicketDetail.Rows(cmbClickedCell.EditingControlRowIndex).Cells("VATRate").Value = "0.00"
End If
End If
End Sub
It works really well for me, unfortunately the user wanted something different in the end ha. Oh well at least i learnt something
I have a ListBox (LB) with a DataTable (DT) DataSource in the Form Class globally populated in the Form_Load event.
Private Sub frmEditPresets_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DT.Columns.Add("DisplayText")
DT.Columns.Add("PresetID")
For Each TSI As ToolStripItem In Presets.DropDownItems
If TSI.Name.IndexOf("preset_") > -1 Then
DT.Rows.Add(TSI.Text, TSI.Name)
End If
Next
LB.DataSource = DT
LB.DisplayMember = "DisplayText"
End Sub
When I use my Rename button. It updates the menu item and the Data Source but the Listbox doesn't refresh until I click another item in the listbox.
Rename code:
Private Sub btnRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRename.Click
Dim R As DataRowView = LB.SelectedItem
Dim S As String = InputBox("Preset Name", "Rename", R("DisplayText"))
If S.Trim.Length = 0 Then Exit Sub
If Presets.DropDownItems.ContainsKey(R("PresetID").ToString) Then
Presets.DropDownItems(R("PresetID").ToString).Text = S
End If
R("DisplayText") = S
End Sub
I'm sure this is a simple question with a simple answer but I can't seem to figure it out. I've tried Refresh(). I've tried setting the DataSource again. I read this StackOverflow question Winforms listbox not updating when bound data changes but ResetBindings() doesn't seem to be an available method in this context.
*Edit. I gave Steve credit for the answer as he mentioned BindingContext. Although, that led me to find BindingContext(DT).EndCurrentEdit() which updated my LB display and maintained the selection.
Tried with this, and it works.....
Private Sub btnRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRename.Click
Dim R As DataRowView = LB.SelectedItem
Dim S As String = InputBox("Preset Name", "Rename", R("DisplayText"))
If S.Trim.Length = 0 Then Exit Sub
If Presets.DropDownItems.ContainsKey(R("PresetID").ToString) Then
Presets.DropDownItems(R("PresetID").ToString).Text = S
End If
R("DisplayText") = S
BindingContext(DT).EndCurrentEdit()
End Sub