Datagrid row heights - very annoying!

Hi all,

I have noticed that if just one row cell has an item which cause the row height to increase, then all the rest of the rows increase in height also.

This is very annoying - any way of stopping the rest of the rows increasing in height??

thanks,


KS
LVL 11
Ramesh SrinivasTechnical ConsultantAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
AerosSagaConnect With a Mentor Commented:
VB Translation:

If i.Cells(2).Text.Length > 25 Then
 e.Item.Cells(2).ToolTip = e.Item.Cells(2).Text
 e.Item.Cells(2).Text = e.Item.Cells(2).Text.Substring(0, 22) + "..."
End If
0
 
AerosSagaCommented:
What item is it text, an image, etc.  Also is the cell wrapping if its text?

Regards,

Aeros
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Yes, it is text, and it is wrapping. Thx.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AerosSagaCommented:
You can either make that specific cell wider or set Pager-Style wrap = false in the properties of the datagrid
0
 
nauman_ahmedCommented:
You can solve it in the following way:

On DataGrid_ItemCreatd event:

if (i.Cells[2].Text.Length > 25)
                        {
                              e.Item.Cells[2].ToolTip = e.Item.Cells[2].Text;
                              e.Item.Cells[2].Text = e.Item.Cells[2].Text.Substring(0,22)+"...";
                              
                        }
This will add a tooltip for the items that has length more than 25 character in the datagrid cell and add three dots after the text that has more than 25 characters.

Best, Nauman
0
 
nauman_ahmedCommented:
and also will trim the lengthy text....:)

HTH, nauman
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Setting wrap to False didn't seem to do anything.

0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Thanks Nauman,

Will try it out and let u know!

Which Microsoft twerp worked on that aspect of the grid :O
0
 
nauman_ahmedCommented:
I think no one :) as it totall depend on how we want to format the grid ;)

Cheers, nauman
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
I'm doing this is in VB.Net Nauman, what is the "i" for ?
0
 
nauman_ahmedCommented:
woops just copy and pasted it from my code it is supposed to be e.Item.Cells[2]. Sorry for the mistake dude..... :)

Best, nauman
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Thats very good, but I still dont know what the "i" variable is.
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Its okay, i got there in the end!
0
 
nauman_ahmedCommented:
actually its nothing :) I have something like the following in the code but then I found I can make it more granular:

foreach(DataGridItem i in dgPublicationsList.Items)
                  {
                        
                        HyperLink h = (HyperLink)i.Cells[1].Controls[0];
                        if (h.Text.Length > 40)
                        {
                              h.ToolTip = h.Text;
                              h.Text = h.Text.Substring(0,37)+"...";      
                        }

                        if (i.Cells[2].Text.Length > 25)
                        {
                              i.Cells[2].ToolTip = i.Cells[2].Text;
                              i.Cells[2].Text = i.Cells[2].Text.Substring(0,22)+"...";
                              
                        }
                                                                  
                  }
But you dont need this whole thing in your code ;)

Best, Nauman
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Assuming the cell numbers refer to the template columns in my grid i did this:

Sub Item_Created(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles DataGrid1.ItemCreated
        If e.Item.ItemType = ListItemType.Item Then
            If e.Item.Cells(7).Text.Length > 10 Then
                e.Item.Cells(7).ToolTip = e.Item.Cells(7).Text
                e.Item.Cells(7).Text = e.Item.Cells(7).Text.Substring(0, 5) + "..."
            End If
        End If
    End Sub 'Item_Created

And also, set the datagrid option: OnItemCreated="Item_Created"

But it doesnt seem to do anything - am i missing something??
0
 
nauman_ahmedCommented:
Change If e.Item.ItemType = ListItemType.Item  to
If e.Item.ItemType = ListItemType.Item or e.Item.ItemType = ListItemType.AlternatingItem

Best, Nauman
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Still nothing! :(
0
 
Ramesh SrinivasTechnical ConsultantAuthor Commented:
Oh well, did this in my ItemDataBound and it worked first time!

If e.Item.ItemType = ListItemType.Item Or _
     e.Item.ItemType = ListItemType.AlternatingItem Then

            Dim thePub As Label
            thePub = CType(e.Item.Cells(7).FindControl("lbl_Publication"), Label)
            If thePub.Text.Length > 25 Then
                thePub.ToolTip = thePub.Text
                thePub.Text = thePub.Text.Substring(0, 22) + "..."
            End If
End if

Upto my boss whether he wants it displayed like this or if he wants to settle for those dirty big rows!!

thanks,

KS
0
All Courses

From novice to tech pro — start learning today.