/// <summary> /// Se abbiamo inserito gli oggeti come dataSource, con CurrentRow.DataBoundItem visualizziamo l'oggetto /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridRoom_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { //Prendiamo l'oggetto selezionato dalla riga Bedroom roomSelect = (Bedroom)dataGridRoom.CurrentRow.DataBoundItem; //Row , ItemArray //Visualizziamo le informazioni base string info = String.Format($"Floor: {roomSelect.Floor}\nRoom: { roomSelect.Room }\nStatus: { roomSelect.Status}"); MessageBox.Show(info, CONST.titleReferenceRoom); }
/// <summary> /// Impostiamo i dati della nostra Tabella alla dataGridView /// </summary> /// <param name="dataGrid"></param> /// <param name="table"></param> public void SetTableInDataGrid(DataGridView dataGrid, DataTable table) { /* * //Metodo veloce per caricare tutti i valori e visualizzare tutti gli elementi come colonne * BindingSource source = new BindingSource { DataSource = table }; * dataGrid.DataSource = source; */ List <Bedroom> RoomsHotel = new List <Bedroom>(); BedroomMetods metods = new BedroomMetods(); foreach (DataRow row in table.Rows) { Bedroom room = metods.ConvertRowToObject(row); RoomsHotel.Add(room); } //Settiamo le colonne della DataGridView var NameField1 = new DataGridViewTextBoxColumn(); NameField1.HeaderText = "Floor"; NameField1.Name = "Floor"; NameField1.DataPropertyName = "Floor"; dataGrid.Columns.Add(NameField1); dataGrid.Columns[NameField1.Name].Frozen = true; var NameField = new DataGridViewTextBoxColumn(); NameField.HeaderText = "Room"; NameField.Name = "Room"; NameField.DataPropertyName = "room"; dataGrid.Columns.Add(NameField); dataGrid.Columns[NameField.Name].Frozen = true; BindingSource source = new BindingSource(); //{ DataSource = RoomsHotel };//{ DataSource = table }; source.DataSource = RoomsHotel; // table; //Load Calendr on dataGridView LoadCalendar(Convert.ToInt32(cbYear.Text), dataGrid); dataGrid.DataSource = source; }