CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2000
    Posts
    29

    Data grid and replace function

    I am using a data grid which i bind to a recordset during run time. But during data retrieval, I have to replace all single quotes with two single quotes. How will i replace the single quotes with two if i am just going to bind the data grid's column datafield to a field in the database? Hope you guys can help me.


  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Data grid and replace function

    In a bound datagrid you cannot replace characters in the grid without changing it in the DB itself. Use unbound grig (MSFlexGrid for example) and enter recordset there replacing any characters you want. If you need code how to enter recordset to msfg, let me know.

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Aug 2000
    Posts
    29

    Re: Data grid and replace function

    can you please give me the code you are saying.


  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Data grid and replace function

    If you use an MSFlexGrid control to display data returned in an ADO recordset, you can use this code to
    dynamically populate the grid-including the header row-with the information in the recordset. You need an
    open ADO recordset named rst and a form containing an MSFlexGrid control named msfGrid:

    Dim cln As Field
    With msfGrid
    .Rows = 2
    .Cols = rst.Fields.Count
    'get the number of grid cols
    .FixedRows = 1
    .FixedCols = 0
    .Row = 0
    .Col = 0
    For Each cln In rst.Fields
    .Text = cln.Name
    'populate header row with names of fields
    If .Col < .Cols - 1 Then .Col = .Col + 1
    Next
    Do While Not rst.EOF
    'loop thru recordset to populate grid
    .Row = rst.AbsolutePosition
    'move to the next row
    .Col = 0
    'reset ourselves back to column(0)
    For Each cln In rst.Fields
    If Not IsNull(cln.Value) Then
    .Text = Trim(CStr(cln.Value))
    Else
    .Text = ""
    End If
    If .Col < .Cols - 1 Then .Col = .Col + 1
    Next
    rst.MoveNext
    .Rows = .Rows + 1
    'add a new row to the grid
    Loop
    .Rows = .Rows - 1
    'remove the last row because it's blank
    .Row = 0
    End With


    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured