Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
275
DataRecord cell exists?
posted

Hello

Is there a way to check if a cell in a DataRecord exists? I have the following code:

void grid_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e)
        {
            if (e.Record is DataRecord)
            {
                DataRecord dr = (DataRecord)e.Record;
                try
                {
                    dr.Cells["No."].Value = (e.Record.Index + 1).ToString();
                }
                catch (Exception ex) { }
            }
        }

 

and I want to remove the try/catch and replace it with something like

if (dr.Cells["No."].Exists) { }

Is there any way to do this?

Many thanks

Kostas.

Parents
No Data
Reply
  • 5
    posted

    This is a pretty old post, but I've run into the same question. Since catching an exception gets really noisy when debugging with "break when exceptions are thrown" enabled, I wanted to get rid of the possible exception that could be thrown. This appears to do that:

    Shared Function GetDataRecordCell(dataRecord As DataRecord, cellName As StringAs Cell
     
    	Contract.Requires(dataRecord IsNot Nothing)
    	Contract.Requires(Not String.IsNullOrWhiteSpace(cellName))
     
    	Dim cell = dataRecord.Cells.SingleOrDefault(Function(c) c.Field.Name = cellName)
    	Return cell
     
    End Function
    

    And it's used like this:

    Dim statusCell = GetDataRecordCell(dr, "Status")
    If statusCell Is Nothing Then Return Binding.DoNothing
    Dim status As String = statusCell.Value
Children
No Data