Still new to WinGrid. Can someone point me to a code example that will accomplish this task? I'm trying to populate text boxes based on a selected UltraGrid row.
Thanks,
-Todd
Hi Todd,
I used "First Name" as an example. You need to use the key of an actual column in your grid.
Oooops! I had to change the if statement to "If (row IsNot Nothing) Then"
But now I'm getting an error on line: "txbxEmpFirstName.Text = row.Cells("First Name").Text"
Here's the exception details:
System.ArgumentException was unhandled by user code Message=Key not foundParameter name: key ParamName=key Source=Infragistics2.Shared.v12.1 StackTrace: at Infragistics.Shared.KeyedSubObjectsCollectionBase.GetItem(String key) at Infragistics.Win.UltraWinGrid.ColumnsCollection.get_Item(String key) at Infragistics.Win.UltraWinGrid.CellsCollection.GetItem(String key) at Infragistics.Win.UltraWinGrid.CellsCollection.get_Item(String key) at iAssist.formEmployee.ultragridEmp_AfterRowActivate(Object sender, EventArgs e) in C:\RRI\MADLab_Collection\Riverside_Internal\iASSIST\iAssist\01 Employee\Employee.vb:line 271 at Infragistics.Win.UltraWinGrid.UltraGrid.OnAfterRowActivate() at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.OnActiveRowChange(UltraGridRow newActiveRow, Boolean scrollIntoView) at Infragistics.Win.UltraWinGrid.UltraGridBase.SetActiveRow(UltraGridRow row, Boolean scrollIntoView) at Infragistics.Win.UltraWinGrid.UltraGrid.EnsureTempActiveRowAssigned() at Infragistics.Win.UltraWinGrid.UltraGridBase.PaintTimer_Tick(Object source, EventArgs e) at Infragistics.Win.UltraWinGrid.RowScrollRegion.set_FirstRow(UltraGridRow value) at Infragistics.Win.UltraWinGrid.UltraGridLayout.ClearMainUIElement() at Infragistics.Win.UltraWinGrid.UltraGridBase.Set_ListManager(Object newDataSource, String newDataMember) at Infragistics.Win.UltraWinGrid.UltraGridBase.BindingListChanged(Object sender, ListChangedEventArgs e) InnerException:
Does any of this make any sense to you? I'm probably missing something simple.
Thanks Mike for your fast response to my question. I failed to mention I'm coding in VB.Net. I took the above code and plugged it into my program.
Private Sub ultragridEmp_AfterRowActivate(sender As Object, e As System.EventArgs) Handles ultragridEmp.AfterRowActivate MsgBox("inside ultragridEmp_AfterRowActivate()") Dim row As UltraGridRow = Me.ultragridEmp.ActiveRow If (row Is Nothing) Then txbxEmpFirstName.Text = row.Cells("First Name").Text txbxEmpLastName.Text = row.Cells("Last Name").Text Else txbxEmpFirstName.Text = String.Empty txbxEmpLastName.Text = String.Empty End If End Sub
When running my program I end up with two issues: First, when populating the grid from the DB, the above subroutine fires as each row is added. Second, I'm not getting any values loading into row when executing "Dim row As UltraGridRow = Me.ultragridEmp.ActiveRow". Every time it hits the "if" statement it goes right to the "else" portion. Any suggestions?
Thanks again,
It really depends on what your goal is and the needs of your application.
If you want to read the data out of the ActiveRow in the grid and assign it to the Textbox manually, then that's easy enough. Something like this:
void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { UltraGridRow row = this.ultraGrid1.ActiveRow; if (row != null) { this.txtFirstName.Text = row.Cells["First Name"].Text; this.txtLastName.Text = row.Cells["Last Name"].Text; } else { this.txtFirstName.Text = string.Empty; this.txtLastName.Text = string.Empty; } }
I've got about 40 columns in my UltraGrid row. When a user clicks on a particular row I want to populate 40 corresponding text boxes on the other side of the form. I'm not 100% sure which of the two choices I should use. Probably would want to go with the second choice, but I suppose I should look at both. Does that sound correct?