When I want to put the values in an array that are selected from a checkedlistbox. And then say:
messagebox.show(values[0]);
It's saying : System.Data.DataRowView
This is my current code:
string[] itemArr = new string[clbTables.CheckedItems.Count];
int counter = 0;
foreach (object item in this.clbTables.CheckedItems)
{
string temp = Convert.ToString(item);
itemArr[counter] = temp;
counter++;
}
MetroMessageBox.Show(this, itemArr[0].ToString());
What am I doing wrong here>?
EDIT ::
clbTables.DataSource = sqlDisplayContent.connectDataTable("SELECT ('Tafelnr: '+ CONVERT(varchar,tafelnr)+' Zitplaatsen: '+ CONVERT(varchar,zitPlaatsen)) AS dispValue,tafelnr FROM tabel");
clbTables.DisplayMember = "dispValue";
clbTables.ValueMember = "tafelnr";
class sqlDisplayContent
{
public static DataTable connectDataTable(string query)
{
SqlCommand comm= sqlCrud.returnSqlCommand(query);
SqlDataAdapter sda = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
Thankss
The issue is that:
will simply call the ToString() method of the object and store that, which in this case, is giving you the object's type. In this case, the type is System.Data.DataRowView. I suggest that you access the specific field in the row that you want by using:
instead. You will want to replace "FieldName" with whatever the name of your column that you are wanting is. Additionally, you can use an int index instead of a string reference. Of course, if you need to access multiple fields, you can do this by simple string concatenation. The issue is that you need to access the specific field that you want. Not the entire row as you are currently on.
I hope this helps!
A couple references: DataRow, DataRowView