Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

binding array to datagridview

Status
Not open for further replies.

decabooter

Programmer
Mar 22, 2013
1
0
0
US
I am a foxpro refugee and would like to know how to bind an array to a datagridview object. My goal is to provide users a way to enter and update the elements in an array.
 
I've personally been using a BindingList of custom objects, that way I can use the ComponentModel to define how exactly I want it displayed in the DataGridView without having to edit the DataGridView itself. To be clear.. I'm not positive of the best practices on this; this has just been working well for me.

in the main application I just do:

Code:
...
[COLOR=#008000]//POPULATE THE MANAGE REPORTS TAB[/color][COLOR=#000000]
currentReportsView.DataSource = _configuration.Reports;[/color]
...

The configuration has a private BindingList that it already populated...

Code:
...
[COLOR=#000000]       [/color][COLOR=#0000FF]public[/color][COLOR=#000000] [/color][COLOR=#2B91AF]BindingList[/color][COLOR=#000000]<[/color][COLOR=#2B91AF]Report[/color][COLOR=#000000]> Reports
       {
         [/color][COLOR=#0000FF]get[/color][COLOR=#000000]
         {
            [/color][COLOR=#0000FF]return[/color][COLOR=#000000] _reports;
         }
         [/color][COLOR=#0000FF]set[/color][COLOR=#000000]
         {
            _reports = [/color][COLOR=#0000FF]value[/color][COLOR=#000000];
         }
       }[/color]
...

And then to control how it is displayed:

Code:
...
[COLOR=#000000]       [[/color][COLOR=#2B91AF]Browsable[/color][COLOR=#000000]([/color][COLOR=#0000FF]false[/color][COLOR=#000000])]
      [/color][COLOR=#0000FF]public[/color][COLOR=#000000] [/color][COLOR=#0000FF]int[/color][COLOR=#000000] ID
      {
          [/color][COLOR=#0000FF]get[/color][COLOR=#000000]
          {
              [/color][COLOR=#0000FF]return[/color][COLOR=#000000] _id;
          }
          [/color][COLOR=#0000FF]set[/color][COLOR=#000000]
          {
              _id = [/color][COLOR=#0000FF]value[/color][COLOR=#000000];
              [/color][COLOR=#0000FF]base[/color][COLOR=#000000].Descendants([/color][COLOR=#A31515]"ID"[/color][COLOR=#000000]).FirstOrDefault().Value = [/color][COLOR=#0000FF]value[/color][COLOR=#000000].ToString();
          }
      }
       [[/color][COLOR=#2B91AF]DisplayName[/color][COLOR=#000000]([/color][COLOR=#A31515]"Report Title"[/color][COLOR=#000000])]
      [/color][COLOR=#0000FF]public[/color][COLOR=#000000] [/color][COLOR=#0000FF]string[/color][COLOR=#000000] ReportName 
       { 
          [/color][COLOR=#0000FF]get[/color][COLOR=#000000]
          { 
             [/color][COLOR=#0000FF]return[/color][COLOR=#000000] _reportName;
          }
          [/color][COLOR=#0000FF]set[/color][COLOR=#000000]
          {
             _reportName = [/color][COLOR=#0000FF]value[/color][COLOR=#000000];
             [/color][COLOR=#0000FF]base[/color][COLOR=#000000].Descendants([/color][COLOR=#A31515]"ReportName"[/color][COLOR=#000000]).FirstOrDefault().Value = [/color][COLOR=#0000FF]value[/color][COLOR=#000000];
          }
       }
       [[/color][COLOR=#2B91AF]DisplayName[/color][COLOR=#000000]([/color][COLOR=#A31515]"Watch Folder"[/color][COLOR=#000000])]
      [/color][COLOR=#0000FF]public[/color][COLOR=#000000] [/color][COLOR=#0000FF]string[/color][COLOR=#000000] Target 
       {
          [/color][COLOR=#0000FF]get[/color][COLOR=#000000]
          {
             [/color][COLOR=#0000FF]return[/color][COLOR=#000000] _target;
          }
          [/color][COLOR=#0000FF]set[/color][COLOR=#000000]
          {
             _target = [/color][COLOR=#0000FF]value[/color][COLOR=#000000];
             [/color][COLOR=#0000FF]base[/color][COLOR=#000000].Descendants([/color][COLOR=#A31515]"Target"[/color][COLOR=#000000]).FirstOrDefault().Value = [/color][COLOR=#0000FF]value[/color][COLOR=#000000];
          }
        }
...[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top