Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Problem with fill method

$
0
0

Hello Everyone:

My problem is a bit strange. Following are the details:

  • I am trying to fill several datagridviews on C# Windows form. Each dataGridView is displaying subsets of data from the Personnel_Tbl
  • In my dataset designer I created a specific fill query. The fill query pulls from thePersonnel_Tbl AND the List_JobRanks table. List_JobRanks is simply a List table with information about job ranks. Specifically it has a field defining colors for each rank. That color field helps me display color-coded data. Following is the SQL statement for my fill Query:
SELECT        Personnel_Tbl.PersonnelID, Personnel_Tbl.LName, Personnel_Tbl.FName, Personnel_Tbl.Rank, Personnel_Tbl.Shift, Personnel_Tbl.StationAssignment, 
                         Personnel_Tbl.HireDate, Personnel_Tbl.BirthDate, Personnel_Tbl.Address, Personnel_Tbl.City, Personnel_Tbl.State, Personnel_Tbl.ZipCode, 
                         Personnel_Tbl.FullName, Personnel_Tbl.Phone1, Personnel_Tbl.Phone1_Desc, Personnel_Tbl.Phone2, Personnel_Tbl.Phone2_Desc, List_JobRanks.RnkColor, 
                         List_JobRanks.RnkOrder
FROM            Personnel_Tbl INNER JOIN
                         List_JobRanks ON Personnel_Tbl.Rank = List_JobRanks.Rank
ORDER BY List_JobRanks.RnkOrder, Personnel_Tbl.FullName
  • When the form loads I use the following fill script
try 
{ 
// Load data into the 'aBC_ShiftDataSet.Personnel_Tbl' table. 
this.personnel_TblTableAdapter.Fill_With_ListRank(this.aBC_ShiftDataSet.Personnel_Tbl); 
Console.WriteLine("loaded with try"); 
} 
catch
{
 Console.WriteLine("Failed to load fill with list rank"); 
}
  • Then on formatting of each DataGridView I use the List_JobRanks.RnkColorfield to define color for each employee's record. I also calculate years of service for each employee and load that number into the datagridview when formatting each DataGridView. Following is the applicable snippet of my formatting script:
                    // Extract RankColor (for each row) from datasource
                    string rnkClr = row.Cells[5].Value.ToString();
                    // Format Cells using rnkClr
                    row.DefaultCellStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#" + rnkClr);

  • Right now everything is working great. The form loads properly. Years of service is loading properly. And the rank color is used properly to color-code each employee record.

But, the kicker is that I can't make any substantive changes to the script without mucking things up. Specifically, I want to add DragDrop routines to each of my DataGridViews. The goal is to allow users to drag/Drop employees from one dataGridView to another.

  • When I add a DragDrop routine to the script something goes haywire with the fill, because my formatting script is NOT picking up theList_JobRanks.RnkColor. Following is the error I receive regarding the formatting script:

NullReferenceException was unhandled by user CodeObject 
Reference not set to an instance of an object

Does anyone have any idea why simply adding a dragdrop routine to one DataGridView would muck up filling from the dataset? It seems as if the formatting script reads myList_JobRanks.RnkColor as null. Meaning (that although I'm not getting any error messages on my try/catch fill routine, the RnkColor routine is picking up a NullReferenceException.

It is beyond me why simply adding a drag/drop routine to one of the DataGridViews would do this. If anyone has any ideas I'd surely appreciate hearing them.

Thanks in Advance -

Pavilion




    Viewing all articles
    Browse latest Browse all 2535

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>