I have an UltraGrid UltraCombo I'm using for a "Work Type" drop-down where user can select multiple Work Types. The datasource I'm connecting to will bring back all work types and also a column that identifies whether or not the column is selected, the value will be True/False for each row.
How do I list all of the work types and have a checkbox selected next to the work type that is "True"?
Dim ds As System.Data.DataSet ds = PTWFormDataAccess.LoadPTWWorkTypes(formid) Me.ddlWorkTypes.DataSource = ds.Tables(0)
Dim c As UltraGridColumn = Me.ddlWorkTypes.DisplayLayout.Bands(0).Columns.Add() c.Key = "Selected" c.Width = 40 c.Header.Caption = String.Empty c.Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always c.DataType = GetType(Boolean) c.Header.VisiblePosition = 0
Me.ddlWorkTypes.CheckedListSettings.CheckStateMember = "Selected" Me.ddlWorkTypes.CheckedListSettings.EditorValueSource = Infragistics.Win.EditorWithComboValueSource.CheckedItems Me.ddlWorkTypes.CheckedListSettings.ListSeparator = " - "
Me.ddlWorkTypes.CheckedListSettings.ItemCheckArea = Infragistics.Win.ItemCheckArea.Item Me.ddlWorkTypes.DisplayMember = "PTWWorkTypeName" Me.ddlWorkTypes.ValueMember = "PTWWorkTypeNamesId" Me.ddlWorkTypes.DropDownWidth = 350 Me.ddlWorkTypes.DisplayLayout.Bands(0).Columns("PTWWorkTypeName").Header.Caption = "Work Type"
The above code gets all work types from the work type table. I have a column called "chk_selected" that is either True or False. I want "Selected" to be checked if "chk_selected" is True.
Hi,
I'm having trouble understanding what you are asking. It sounds like you already have a boolean column in your data source, so why are you creating an additional unbound column? It sounds like you want both columns to contain the same value. So why have two columns? Why not just use "chk_selected" as your CheckStateMember directly?
Thank you for the reply. Yes I am doing that now.
I thought I needed to add a "Selected" column for the checkbox? This code creates the checkbox but I can't select/checkmark the checkboxes:
Sub LoadPermitWorkTypes() 'pass in PTWFormId Dim ds As System.Data.DataSet ds = PTWFormDataAccess.LoadPTWWorkTypes(Me.PTWFormId) Me.ddlWorkTypes.DataSource = ds.Tables(0)
Me.ddlWorkTypes.CheckedListSettings.CheckStateMember = "chkSelected" Me.ddlWorkTypes.CheckedListSettings.EditorValueSource = EditorWithComboValueSource.CheckedItems
Me.ddlWorkTypes.CheckedListSettings.ItemCheckArea = ItemCheckArea.Item Me.ddlWorkTypes.DisplayMember = "PTWWorkTypeName" Me.ddlWorkTypes.ValueMember = "PTWWorkTypeNamesId" Me.ddlWorkTypes.DropDownWidth = 350 Me.ddlWorkTypes.DisplayLayout.Bands(0).Columns("PTWWorkTypeName").Header.Caption = "Work Type" End Sub
This code gives me "chkSelected" as True and False values, but its not rendering a checkbox:
Sub LoadPermitWorkTypes() 'pass in PTWFormId Dim ds As System.Data.DataSet ds = PTWFormDataAccess.LoadPTWWorkTypes(Me.PTWFormId) 'Hide Suspended rows on Initialize Row event Me.ddlWorkTypes.DataSource = ds.Tables(0)
winform_developer said:I thought I needed to add a "Selected" column for the checkbox?
Well, you can create an unbound column, but you don't necessarily have to. If you already have a boolean column in your data source, then there's no reason to create an additional one - you could just use the column you already have. Of course, I am assuming that the column is editable in the data source. If the data source will not allow you to edit that column, it won't be suitable for selection. But if that's the case, the unbound column won't help, because you won't be able to change the value of the bound column no matter what.
I figured it out. I just needed to get the work types from the correct drop down. I have one for new forms, and one for work types that are populated by the datasource on updates to a form.
My code worked fine.
Thank you.
Per your comment:
Of course, I am assuming that the column is editable in the data source
I'm using a stored proc with a temp table as my datasource. how would I make the column editable?
Thanks.
I now have the work types selected form the datasource. My only issue now is that when I save, even though the work type(s) are selected correctly, my app isn't recognizing that's it's selected.
In my stored procedure, I created a temp table where I could define "chkselected" as a BIT then use that temp table as my datasource.
Any ideas?
Sub LoadPermitWorkTypes() Dim ds As System.Data.DataSet ds = PTWFormDataAccess.LoadPTWWorkTypes(Me.PTWFormId) 'Hide Suspended rows on Initialize Row event Me.ddlPermitWorkTypes.DataSource = ds.Tables(0)
Me.ddlPermitWorkTypes.Rows.Band.Columns("chkSelected").Width = 40 Me.ddlPermitWorkTypes.Rows.Band.Columns("chkSelected").Header.Caption = String.Empty Me.ddlPermitWorkTypes.Rows.Band.Columns("chkSelected").Header.CheckBoxVisibility = HeaderCheckBoxVisibility.Always Me.ddlPermitWorkTypes.Rows.Band.Columns("chkSelected").Header.VisiblePosition = 0
Me.ddlPermitWorkTypes.CheckedListSettings.CheckStateMember = "chkSelected" Me.ddlPermitWorkTypes.CheckedListSettings.EditorValueSource = EditorWithComboValueSource.CheckedItems
Me.ddlPermitWorkTypes.CheckedListSettings.ItemCheckArea = ItemCheckArea.Item Me.ddlPermitWorkTypes.DisplayMember = "PTWWorkTypeName" Me.ddlPermitWorkTypes.ValueMember = "PTWWorkTypeNamesId" Me.ddlPermitWorkTypes.DropDownWidth = 350 Me.ddlPermitWorkTypes.DisplayLayout.Bands(0).Columns("PTWWorkTypeName").Header.Caption = "Work Type" End Sub
my SQL code:
DECLARE @TempPTWWorkTypes as TABLE ([PTWWorkTypeName] VARCHAR(200), [PTWWorkTypeNamesId] UNIQUEIDENTIFIER, [Suspended] BIT, [chkSelected] BIT)
(...fill the temp table with data...)
SELECT [PTWWorkTypeName], [PTWWorkTypeNamesId], [Suspended], [chkSelected]FROM @TempPTWWorkTypes ORDER BY [PTWWorkTypeName]