0

I have a GridView in my form and I want when I click on a button to open another form and fill it with informations from the selected row in the GridView.

This is the code I tried in the form that contains the GridView:

private void barButtonItem13_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
   DataRow getRow = gridView1.GetDataRow(gridView1.GetSelectedRows()[0]);
   using (Collections_.ModifierCollection modifierCollection = new Collections_.ModifierCollection((string)getRow[1],(string)getRow[2]))
   {
      var result = modifierCollection.ShowDialog();
      if (result == DialogResult.OK)
      {
          // Just some code that I used
      }
   }
}

And this is the code I tried in that other form:

public ModifierCollection(String getKeyWordCollectionName, String getKeyWordEditeurName)
{
  collectionBox.Text = String.IsNullOrEmpty(getKeyWordCollectionName) ?
                                 "unknown" :
                                 getKeyWordCollectionName;
        editeurBox.Text = String.IsNullOrEmpty(getKeyWordEditeurName) ?
                              "unknown" :
                              getKeyWordEditeurName;
  InitializeComponent();
}

But it gives me an error in this line: collectionBox.Text = getKeyWordCollectionName;

Object reference not set to an instance of an object.

nbanic
  • 1,248
  • 1
  • 8
  • 11
Spoon Yukina
  • 525
  • 4
  • 13
  • 26
  • possible duplicate: [what is a nullreferenceexception](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) – Default Sep 30 '12 at 15:08
  • 1
    most likely your `collectionBox` isn't created. try to move it after `InitializeComponent()` – Default Sep 30 '12 at 15:10

2 Answers2

2

Most likely your collectionBox isn't created. Try to move it after InitializeComponent()

Default
  • 10,565
  • 8
  • 60
  • 99
0

use Value property in Cell of datagridviewRow

a d
  • 542
  • 2
  • 7
  • 17
  • you cast a dataRow to String. but you are 1)Work with DatagridviewRow 2)Work with Value property in datagridviewRow 3)pass it between 2 form – a d Sep 30 '12 at 15:25
  • please short your question . your question is very tall – a d Sep 30 '12 at 15:41