Ren
Ren

Reputation: 775

Set value and string in datagridview

this question might be very basic. But I just want to make this clear:

lets say I have a code like :

string currentToner = (string)((Hashtable)ht[1])["value"];
string maxToner = (string)((Hashtable)ht[2])["value"];

Now I want to set this value in data grid view.

int number = dataGridView1.Rows.Add();
dataGridView1.Rows[number].Cells[0].Value = currentToner."/".maxToner;  //-->this is not the correct way.

How to set the value so that it looks something like:

5000/10000

Upvotes: 1

Views: 935

Answers (2)

meda
meda

Reputation: 45490

You are doing it the PHP way, in C# string concatenation is done with plus signs

dataGridView1.Rows[number].Cells[0].Value = currentToner + "/" + maxToner; 

You can format the string as well

dataGridView1.Rows[number].Cells[0].Value = string.Format("{0}/{1}", currentToner, maxToner); 

Upvotes: 1

quantdev
quantdev

Reputation: 23793

If you want to display a string, set a string as the value :

dataGridView1.Rows[number].Cells[0].Value = currentToner + "/" + maxToner;

Upvotes: 1

Related Questions