【问题标题】:Radio group in devexpress grid controldevexpress 网格控件中的单选组
【发布时间】:2016-01-28 06:56:32
【问题描述】:

我需要在 devExpress 网格控件 (grdDisb) 中使用无线电组 (rdoChargeOn)。 我正在从存储过程中获取行。 我总是选择无线电组的索引= -1,值= 0的问题。 此外,如果我创建一个新行,则单击 enter 后值为 0,没有选定项目。

在这种情况下,rdochargeOn.SelectedIndex 的等价物是什么?你能帮我吗? 请查找附加的网格打印屏幕。

    Private _DisbList As BindingList(Of PropertyDisbursementList)
 _DisbList = New BindingList(Of PropertyDisbursementList)(obj.DisbList)
 GrdDisb.DataSource = _DisbList
 GrdDisb.RefreshDataSource()

rivate Sub BindDisbGrid()
        If RecordId <> -1 Then '' Import the list of disbursement 
            _DisbList = New BindingList(Of PropertyDisbursementList)(obj.DisbList)
        End If
        _DisbList.AllowNew = True
        GrdDisb.DataSource = _DisbList
        GrdDisb.RefreshDataSource()
    End Sub
    Public Sub SaveDisbList()
        Try
            Dim disb As New PropertyDisbursementList
            Dim indx As Int32 = 0
            Dim CategName As String = ""
            Dim objWCF As WCFReference.PropertiesServiceProvider = GetServiceProvider()
            For i As Integer = 0 To GridView1.DataRowCount - 1
                If GridView1.GetRowCellValue(i, "CategId").ToString <> 0 Then
                    disb = _DisbList(i)
                    If RecordId <> -1 Then
                        disb.PropertyId = RecordId
                        disb.CategName = objWCF.Service.GetCatPropertyDisbursement(disb.CategId)
                        disb.RecordInfo = GetRecordInfo()
                        disb.PropertyId = objWCF.Service.SavePropertyDisbursementList(disb)
                    Else
                        disb.PropertyId = ProId
                        disb.CategName = objWCF.Service.GetCatPropertyDisbursement(disb.CategId)
                        disb.RecordInfo = GetRecordInfo()
                        disb.PropertyId = objWCF.Service.SavePropertyDisbursementList(disb)
                    End If
                End If
            Next
        Catch ex As Exception
            iMessage.ShowError(Nothing, ex)
        End Try
    End Sub

提前谢谢, 问候, 哈迪尔

【问题讨论】:

    标签: vb.net devexpress


    【解决方案1】:

    浏览这个 DevExpress 线程 - Radio Group as Repository Item not working for multiple rows

    我怀疑这个问题可能是您没有向 RadioGroup 控件添加与网格当前单元格的值匹配的项目。

    检查这个例子 -

    List<int> uncheckedID = new List<int>();
    
    public Form2()
    {
        InitializeComponent();
        gridControl1.DataSource = CreateTable(10);
    
    }     
    private static DataTable CreateTable(int RowCount)
    {
        Random rnd = new Random();
        DataTable tbl = new DataTable();
        tbl.Columns.Add("Name", typeof(string));
        tbl.Columns.Add("ID", typeof(int));
        tbl.Columns.Add("Number", typeof(int));
        tbl.Columns.Add("Date", typeof(DateTime));
        for (int i = 0; i < RowCount; i++)
            tbl.Rows.Add(new object[] { String.Format("Name{0}", i), i, i % 3, DateTime.Now.AddHours(i) });
        return tbl;
    }  
    private void gridView1_CustomDrawRowFooterCell(object sender, DevExpress.XtraGrid.Views.Grid.FooterCellCustomDrawEventArgs e)
    {
        e.Info.DisplayText = "Total value for " + gridView1.GetGroupRowValue(e.RowHandle).ToString() + " = " + e.Info.Value;
    }
    
    private void gridView1_ShownEditor(object sender, EventArgs e)
    {
        ColumnView view = (ColumnView)sender;
        if (view.FocusedColumn.FieldName == "Number" && view.ActiveEditor is RadioGroup)
        {
            RadioGroup edit = (RadioGroup)view.ActiveEditor;
            //You can add the items at run time.
            edit.Properties.Items.AddRange(new DevExpress.XtraEditors.Controls.RadioGroupItem[] 
            {
                new DevExpress.XtraEditors.Controls.RadioGroupItem(0, "Item 1"),
                new DevExpress.XtraEditors.Controls.RadioGroupItem(1, "Item 2"),
                new DevExpress.XtraEditors.Controls.RadioGroupItem(2, "Item 3")
            });
        }
    }
    

    使用网格的 ShownEditor 事件绑定编辑器控件中的值,以便它将选定的项目设置在组中..

    希望有帮助

    【讨论】:

    • 不幸的是,我在链接“Radio Group as Repository Item not working for multiple rows”的示例中做了相同的表示,但我仍然有相同的 pbm。
    猜你喜欢
    • 2013-10-21
    • 2011-07-07
    • 1970-01-01
    • 2011-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    相关资源
    最近更新 更多