Solved

Datagrid row heights - very annoying!

Posted on 2004-08-18
18
312 Views
Last Modified: 2010-04-07
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
0
Comment
Question by:saleek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 3
18 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11831577
What item is it text, an image, etc.  Also is the cell wrapping if its text?

Regards,

Aeros
0
 
LVL 11

Author Comment

by:saleek
ID: 11831657
Yes, it is text, and it is wrapping. Thx.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11831715
You can either make that specific cell wider or set Pager-Style wrap = false in the properties of the datagrid
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11831785
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
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11831794
and also will trim the lengthy text....:)

HTH, nauman
0
 
LVL 11

Author Comment

by:saleek
ID: 11831819
Setting wrap to False didn't seem to do anything.

0
 
LVL 11

Author Comment

by:saleek
ID: 11831867
Thanks Nauman,

Will try it out and let u know!

Which Microsoft twerp worked on that aspect of the grid :O
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11831941
I think no one :) as it totall depend on how we want to format the grid ;)

Cheers, nauman
0
 
LVL 11

Author Comment

by:saleek
ID: 11831970
I'm doing this is in VB.Net Nauman, what is the "i" for ?
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 50 total points
ID: 11832014
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
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11832024
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
 
LVL 11

Author Comment

by:saleek
ID: 11832034
Thats very good, but I still dont know what the "i" variable is.
0
 
LVL 11

Author Comment

by:saleek
ID: 11832077
Its okay, i got there in the end!
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11832093
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
 
LVL 11

Author Comment

by:saleek
ID: 11832203
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
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11832280
Change If e.Item.ItemType = ListItemType.Item  to
If e.Item.ItemType = ListItemType.Item or e.Item.ItemType = ListItemType.AlternatingItem

Best, Nauman
0
 
LVL 11

Author Comment

by:saleek
ID: 11832331
Still nothing! :(
0
 
LVL 11

Author Comment

by:saleek
ID: 11832472
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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question