DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18

    Formatting datagridview cells after databinding

    I have a datagridview in a control. After databinding I want to make some changes to the text of some of the cells. I have tried doing it on cellFormatting and dataBindingComplete both cause a loop. Is there an easy way of doing this?

  2. #2
    Join Date
    Sep 2008
    Posts
    86
    how is the datagridview databound? if it's to a DataTable or DataSet, you can edit those before binding.

    If not, then sorry, DataBindingComplete is probably your next option. Unlike the GridView in ASP.Net which allows you to use code to handle each individual row as it's databound, the DataGridView with Windows Programming does not.
    Last edited by eclipsed4utoo; 12-16-2008 at 09:06 AM.

  3. #3
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18
    This is a Windows Forms application and I am binding to a DataTable. The control I have consists of the datagridview and some buttons. The datagridview gets bound to various datatables provided by the form on which the control is used. I was hoping to deal with a particular column in the controls and not have to pre-format the column in the datatable every time I use the control.
    The formatting I am doing is stripping out RTF tags. Unfortunately this is not very efficient in SQL.

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,651
    Try switching to an unbound control and load it by programming code at which time you strip out the RTF tags.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18
    I've done something similar. I do a "for each row" in the datagrid and fix the text. Problem is I have to do this from outside of the control and every time I use the control. I was hoping to build it into the control that it fixed itself as it bound.

  6. #6
    Join Date
    Sep 2008
    Posts
    86
    you can make your own control.

  7. #7
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18
    I tried to create a custom RTF column but couldn't get it to work. I see there is a new article out regarding this. I was going to review it shortly.
    Basically I inherited a textbox column and then I have a function which creates an instance of the RichTextBox, taking the RTF text and returning it as plain text. This would have created a non-formatted but human readable text column. Problem is that the textbox cell leaves enough space for the full RTF text. Once I formatted the cell content, I was left with a chunk of white space at the bottom of each cell.

Similar Threads

  1. DataGridView - How do I...
    By Wiseman82 in forum .NET
    Replies: 2
    Last Post: 05-02-2008, 05:51 PM
  2. DataGridView formatting breaks validation
    By jellyfish5000 in forum .NET
    Replies: 5
    Last Post: 02-23-2007, 05:46 PM
  3. DataGridView Returning Values from Cells
    By triley35 in forum .NET
    Replies: 1
    Last Post: 07-08-2006, 12:34 AM
  4. ASP.NET - Update database with databinding
    By MichaelChoi in forum ASP.NET
    Replies: 2
    Last Post: 01-15-2003, 07:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links