CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Apr 2009

    Calling a field and replace

    I am trying to call/isolate the field InspectionSummary.InspectionSummaryDate so I can do a Replace on it. Basically replace all "-" with "/".

    I can't seem to be able to do a Replace from the SQL. I am wondering how in Section #1 or #2 I could
    reformat the field value before it appears in the StackPanel.

    private void FillDataGrid()
                ArrayList permitTypes = new ArrayList();
                permitTypes = control.GetSummaryTypes(currentJobID);
                if (permitTypes.Count > 0)
                    for (int i = 0; i < permitTypes.Count; i++)
                        //Get the summaries for each type
                        DataView dv = control.GetSummary(currentJobID, permitTypes[i].ToString());
                        //Check to see if there are rows and if so add the Panel
                        if (dv.Table.Rows.Count > 0)
                            Expander ex1 = new Expander();
                            ex1.Header = permitTypes[i].ToString();
                            DataGrid dgList = new DataGrid();
                            ex1.Content = dgList;
                            dgList.ItemsSource = dv;
                            //Draw a line between each card dropdown expander panel
                            Line line = new Line();
                            line.X1 = 0;
                            line.X2 = ex1.ActualWidth - 1;
                            line.Y1 = 0;
                            line.Y2 = ex1.ActualHeight - 1;
                            line.Stroke = Brushes.Black ;
                            line.StrokeThickness = 2; 
    public DataView GetSummary(int jobID, string permitType){
                //Set the DBCommand object
                DataSet jobDataSet = null;
                IDataParameter[] paramCollection = new IDataParameter[2];
                OleDbParameter p_JobID = new OleDbParameter("JobID", jobID);
                paramCollection[0] = p_JobID;
                OleDbParameter p_permitType = new OleDbParameter("PermitType", permitType);
                paramCollection[1] = p_permitType;
                jobDataSet = db.ExecuteDataSet(GET_SUMMARY_LIST, CommandType.Text, paramCollection);
                return jobDataSet.Tables[0].DefaultView;
      const string GET_SUMMARY_LIST = "SELECT InspectionSummary.InspectionType, InspectionSummary.Status,  " +
    "InspectionSummary.Inspector,  left(InspectionSummary.InspectionSummaryDate,10) as  Dates " +  
    "FROM InspectionType INNER JOIN InspectionSummary ON InspectionType.InspectionTypeName = InspectionSummary.InspectionType"  + 
    "WHERE InspectionSummary.JobID=@JobID AND InspectionSummary.PermitType=@PermitType ORDER BY InspectionSummary.InspectionSummaryDate;";
    Last edited by gstercken; May 15th, 2009 at 05:19 AM. Reason: Added code tags

  2. #2
    Join Date
    Jan 2009

    Re: Calling a field and replace

    Here is one possibility:

    1) Create a handler for the DataGrid.AutoGeneratingColumn event
    2) In the DataGrid.AutoGeneratingColumn event, examine the column header values looking for the one you want (I guess this would be InspectionSummaryDate in your case)
    3) When you find the column header that corresponds to the one you are looking for, create a new Binding using "InspectionSummaryDate" as the Path
    4) Implement an IValueConverter (see MSDN) that takes the summary dates and converts them into the format you wish
    5) Create an instance of the value converter and assign it to the Converter property of the Binding you set up earlier
    6) In the AutoGeneratingColumn handler, set e.Column to the binding that you just created. This will require some casting, but it should be straightforward

    Let me know if that is not clear. I tried to just summarize the process that I have tried before.

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.