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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

column error on datagrid

Status
Not open for further replies.

ernatlas

Programmer
Jan 17, 2007
8
0
0
MX
Hello, can anyone help me. I hava a datagrid withd one column. I wanna fill the column with all the values that i get from a selection in mysql. The problem is that when i want to add a value on my datagrid(mysqlTable) in column 1, i get an exception. I can only add at index 0. As if i wheren't able to increase the size of rows.


res = mysql.hazConsulta("select * from consul;");
if(res.HasRows)
while (res.Read())
{
// here is when the exception happens, when i = 1
mysqlTable[i++, 0].Value = "" + res.GetString(0);
}


Can anyone help me??
 
I used a DataGridView to collect data from other classes, firstly you have to store data in strings then you add these string arrays to your DatagridView.
Probably this sample can be helpful


dataGridView1.Columns[0].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Bold);
// Create the string array for each row of data.
string[] row0 = {"USER_ID", MultiRadioManager.usrID };
string[] row1 = {"USER_PSW", MultiRadioManager.usrPwd };
string[] row2 = {""BROKER_IP"", MultiRadioManager.brokerIP };
string[] row3 = {"BROKER_PORT", MultiRadioManager.brokerPort.ToString() };

// Add a row for each string array.
{
DataGridViewRowCollection rows = this.dataGridView1.Rows;
rows.Add(row0);
rows.Add(row1);
rows.Add(row2);
rows.Add(row3);
rows.Add(row4);
}

Regards
Zendani Mohamed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top