0

I Need help adding a button to a cell of my DataGridView. It's not working with the code i'm using (see below).

I'm getting an error: No best type found for implicity-typed Array

DataGridViewButtonCell btn = new DataGridViewButtonCell();
this.dataGridView1[0,100] = btn;
this.dataGridView1[0,100].Value = "Button";

What i'm trying to accomplish is to add the 2nd column on this row with a button: (but it's not working)

dataGridView1.Rows.Add(new[] { "A:", (button goes here) , textbox1.Substring(648 , 2) })

2
  • The second line should have worked and made the 1st cell in the 100th row a buttonCell. If it exists. The 4th line makes no sense. Commented May 17, 2019 at 15:54
  • Adding a row wouldn't be replacing a row. Commented May 17, 2019 at 19:19

1 Answer 1

1

Try this :

int index = DataGridView1.Rows.Add("Test1", "Test2", "Test3");
DataGridView1.Rows[index].Cells[2] = New DataGridViewButtonCell(){ Value = DataGridView1.Rows[0].Cells[2].Value}
Sign up to request clarification or add additional context in comments.

6 Comments

A btn is a string?
Oops! Let me try something. I'll test using object instead of string. I didn't see you were trying to insert 2 string and your button.
I updated my answer. I tried thoses 2 very lines in VB.Net with success.
Use the @name format in comments to reply to someone. You should use the returning index of the row: int index = DataGridView1.Rows.Add("Test1", "Test2", "Test3"); Then you can use that index: DataGridView.Rows[index].Cells...
Ok thanks @LarsTech I'll update the answer with your suggestion.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.