I have a datagridview that has cells with text values that have "True" for one column and the next column should have a Combobox with two values to choose from (in and out)... I want to change the cell type to be a check box and cell type to Combobox... if the cell text is "true" the checkbox must be checked and if it is false or there is nothing in it, it must be unchecked if text from the direction column is in the Combobox value must be set to IN and have an extra option of out in it ... this DATA comes from a loaded XML file, this is how I load the XML file to the datagridview
public void Load(DataGridView dgv)
{
dgv.Refresh();
XmlReaderxmlFile = XmlReader.Create(@"path/DGVXML.xml",newXmlReaderSettings());
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlFile);
dgv.DataSource = dataSet.Tables[0];
xmlFile.Close();
}
the datagridview must display as follows
this is what iv added to the load method and worked 100%
dgv.Refresh();
XmlReader xmlFile = XmlReader.Create(@"/DGVXML.xml", new XmlReaderSettings());
DataSet dataSet = new DataSet();
dataSet.ReadXml(xmlFile);
DataGridView grid = new DataGridView();
var nameColumn = new DataGridViewTextBoxColumn();
nameColumn.Name = "Device Name";
nameColumn.HeaderText = "Device Name";
dgv.Columns.Add(nameColumn);
var checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.Name = "Select";
checkColumn.HeaderText = "Select";
dgv.Columns.Add(checkColumn);
string IN = "IN";
string OUT = "OUT";
var select = new DataGridViewComboBoxColumn();
select.HeaderText = "Direction";
select.Name = "Direction";
select.Items.Add(IN);
select.Items.Add(OUT);
dgv.Columns.Add(select);
foreach (DataRow row in dataSet.Tables[0].Rows)
{
string DeviceName = row[0].ToString();
bool Enabled = false;
if (row[1].ToString() != "")
Enabled = Convert.ToBoolean( row[1].ToString());
string Direction = row[2].ToString();
DataGridViewRow dgRow = new DataGridViewRow();
dgv.Rows.Add(new object[] {DeviceName, Enabled, Direction});
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments