DataGridview에 정보가 있는지에 따라 단추의 텍스트를 굵게 설정할 수 있습니까? 다음은 데이터 글보기에 정보가 있는지에 따라 단추의 텍스트를 굵게 설정할 수 있습니까?
은 샘플 프로젝트 - Windows 응용 프로그램을 작성하고이 코드를 넣어는 내가하고 싶은 것은 필드는 정보가있는 경우 나 해당 셀 버튼 글꼴을 굵게 할 것입니다..
이 당신을 도울 것입니다
가private void Form1_Load(object sender, EventArgs e) {
DataTable table = GetTable();
DataGridViewColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "Dosage";
col.Width = 80;
int colIndex = dataGridView1.Columns.Add(col);
DataGridViewColumn col2 = new DataGridViewTextBoxColumn();
col2.HeaderText = "Drug";
col2.Width = 75;
colIndex = dataGridView1.Columns.Add(col2);
DataGridViewColumn col3 = new DataGridViewTextBoxColumn();
col3.HeaderText = "Patient";
col3.Width = 75;
colIndex = dataGridView1.Columns.Add(col3);
DataGridViewColumn col4 = new DataGridViewTextBoxColumn();
col4.HeaderText = "Date";
col4.Width = 40;
colIndex = dataGridView1.Columns.Add(col4);
DataGridViewButtonColumn buttonCol = new DataGridViewButtonColumn();
buttonCol.Name = "btnNotes";
buttonCol.HeaderText = "Notes";
buttonCol.Text = "Notes";
buttonCol.Width = 80;
buttonCol.UseColumnTextForButtonValue = true;
buttonCol.DefaultCellStyle.Font = new Font("Arial", 12, FontStyle.Bold);
dataGridView1.Columns.Add(buttonCol);
// Add items to the grid
int i = 0;
foreach(DataRow rows in table.Rows) {
dataGridView1.Rows.Add();
dataGridView1[1, i].Value = rows[0].ToString();
dataGridView1[1, i].Value = rows[1].ToString();
dataGridView1[2, i].Value = rows[2].ToString();
dataGridView1[3, i].Value = rows[3].ToString();
if (rows[3].ToString().Trim().Length != 0) {
//Because there are notes in this field, I would like to set this button text only to bold
}
i++;
}
}
static DataTable GetTable() {
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("BlaBlaBla", typeof(string));
table.Rows.Add(25, "Indocin", "David", "Notes in here");
table.Rows.Add(50, "Enebrel", "Sam", "");
table.Rows.Add(10, "Hydralazine", "Christoff", "");
table.Rows.Add(21, "Combivent", "Janet", "Notes in here");
table.Rows.Add(100, "Dilantin", "Melanie", "");
return table;
}
은 ... 작동하지 않습니다 – Rob
복사 오류를 붙여주세요. –
샘플을 제공하도록 코드를 업데이트했습니다. 귀하의 코드가 어떻게 적용되는지 알려주십시오. 감사. – Rob