This is a migrated thread and some comments may be shown as answers.

Upgrade to Q3 2010 : CellFormatting problem

9 Answers 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 22 Nov 2010, 10:52 AM
Hello,

I have upgraded Telerik for Winforms to version Q3 2010 (version 2010.3.10.1109) .
In the _CellFormatting-event I add a RadComboBoxElement to a cell.
Since new version the event behaves strange or different.
e.CellElement.RowIndex is always -1 ?
void gridPositionen_CellFormatting(object sender, CellFormattingEventArgs e)
{
       if (e.CellElement.ColumnInfo is GridViewDataColumn && ((GridViewDataColumn)e.CellElement.ColumnInfo).Name == "Me_Dropdown")
       {
       
          if (e.CellElement.Children.Count > 0 || e.CellElement.RowIndex<0)//the comboxbox is already added to cell                        
          return;
 
                    
//NEVER GETS HERE !!!!  e.CellElement.RowIndex is always -1
 
 
                    RadComboBoxElement element = new RadComboBoxElement();
                    e.CellElement.Children.Add(element);
....



How do I get the RowIndex in the CellFormatting-event ? Or is there a new way to add a RadComboBoxElement to a cell ?




9 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 11:25 AM
Hi,

Yes, you can get the RowIndex
private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.RowIndex > -1)
    {
        MessageBox.Show(e.CellElement.RowIndex.ToString());
    }
}

Have a look at Emanuel's answer here which has a combobox column in the code.

Hope that helps but let me know if oyu have further questions
Richard
0
Fred
Top achievements
Rank 1
answered on 22 Nov 2010, 11:29 AM
Thx !

0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 11:35 AM
No problem. Please remember to mark as answer if this has helped.
Thanks
Richard
0
Fred
Top achievements
Rank 1
answered on 22 Nov 2010, 12:10 PM
Ok I will Richard, but I have found the problem or bug. See following exemple :
public testform()
       {
           InitializeComponent();
           radGridView1.CellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(radGridView1_CellFormatting);
 
           radGridView1.BeginUpdate();
           radGridView1.Columns.Add("ID", "ID");
           radGridView1.Columns.Add("NAME", "NAME");
           radGridView1.Rows.Add(1, "John");
           radGridView1.Rows.Add(2, "Bill");
           radGridView1.Rows.Add(3, "Ronald");
           radGridView1.EndUpdate();
       }
 
       void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
       {
           int i = e.CellElement.RowIndex;
       }
in this exemplee.CellElement.RowIndex is always -1

if I remove radGridView1.BeginUpdate(); and radGridView1.EndUpdate(); from the code then
e.CellElement.RowIndex is not always -1.

A bug ?
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 01:03 PM
Hello,

Another way to get the RowIndex as it appears that it is always -1 when you wrap with BeginUpdate / EndUpdate is in the following way (inside CellFormatting event)

Dim index As Integer = Me.RadGridView1.Rows.IndexOf(e.CellElement.RowInfo)
MessageBox.Show(index.ToString())

hope this helps
Richard
0
Fred
Top achievements
Rank 1
answered on 23 Nov 2010, 09:12 AM
RowInfo is also empty . Your function also returns -1.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 23 Nov 2010, 10:11 AM
Hello Fred,

Whilst e.CellElement.RowIndex is always -1 when wrapped in a BeginUpdate / EndUpdate, the above code always returns the correct index for me. (-1 will be returned for header rows)
Please can you try this sampple in a new project. It's just a RadGridView on a form.

Thanks
Public Class Form1
  
    Public Sub New()
        InitializeComponent()
    End Sub
  
    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
  
        RadGridView1.BeginUpdate()
        RadGridView1.Columns.Add("ID", "ID")
        RadGridView1.Columns.Add("NAME", "NAME")
        RadGridView1.Rows.Add(1, "John")
        RadGridView1.Rows.Add(2, "Bill")
        RadGridView1.Rows.Add(3, "Ronald")
        RadGridView1.EndUpdate(True)
  
    End Sub
  
    Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, _
        ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
  
  
        Dim index As Integer = Me.RadGridView1.Rows.IndexOf(e.CellElement.RowInfo)
        If index > -1 Then
            MessageBox.Show(index.ToString())
        End If
    End Sub
  
End Class
Richard
0
Fred
Top achievements
Rank 1
answered on 23 Nov 2010, 10:20 AM
Ok, this works, thanks for your time !
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 23 Nov 2010, 10:21 AM
You're welcome Fred. Glad that worked for you.
Richard
Tags
GridView
Asked by
Fred
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Fred
Top achievements
Rank 1
Share this question
or