Hello,
I have an ultracombo in the ultragrid. I would like to set the default value to "N/A" to the ultracombo from the dataset. Please help me out and below is the code and I don't know where im making a mistake.
Private Sub BindJurisdictionDropDown() JurisDT = GetJuris.Tables(0)-------{"AB","BC","CD","N/A"} ucb_Juri.SetDataBinding(JurisDT , Nothing) ucb_Juri.ValueMember = "JurisID" ucb_Juri.DisplayMember = "Juris" End Sub
Private Sub UG_InitializeLayout(sender As Object, e As UltraWinGrid.InitializeLayoutEventArgs) Handles UG.InitializeLayout
Try
With e.Layout.Bands(0) .Columns("JID").TabStop = True
.Columns("JID").ValueList = ucb_Juri
.Columns("JID").MinWidth = 25 .Columns("JID").Style = ColumnStyle.DropDownList
For Each row As UltraGridRow In ucb_Juri.Rows()
If row.Cells("JID").Text = "N/A" Then
ucb_Juri.SelectedRow = row End If Next
End With
Catch
end Sub
Thanks,
AB
Hi AB,
Thank you for posting in our forums.
There are a few ways to do this. You can use the InitializeRow event of the UltraGrid and if the row is initialized for the first time, set the value of the cell to “N/A”:
Private Sub UltraGrid1_InitializeRow(sender As Object, e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) Handles UltraGrid1.InitializeRow
If e.ReInitialize = False Then
e.Row.Cells(“JID”).Value = "N/A"
End If
End Sub
An alternative approach, would be to set a default value for the column in the grid data table, before adding any rows:
GridDataTable.Columns("JID").DefaultValue = "N/A"
Please let me know if you have any additional questions.
Hello Dimitar,
I have tried using those 2 approaches before but it gives me error when I save as I'm saving its ID and not the text in the database.
Ex: Here is the datatable for the ultracombo with in the ultragrid.
1 AB
2 BC
3 CD
4 N/A
For this one when I save it should automatically select the value as 4 and text as N/A.
AB.
Thank you for the reply.
If the column of the grid is an integer then you should initialize it to an integer (4 in your case). As long as you have properly set the Value and Display members of the combo, the value that will be returned to the grid will be the integer and the string will be displayed in it.
I have attached a sample which demonstrates this suggestion. If you are still struggling to implement this, please modify my sample in order to demonstrate your issue.
Dimitar,
I made changes to the Initialize row event and it worked out.
For Each row As UltraGridRow In ucb_Juris.Rows() If row.Cells("Juris").Text = "N/A" Then e.Row.Cells("Jury Name").Value = row.Cells("JurisID").Value End If Next End If