DefaultCellStyle
How do I use Default Cell Style
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
81 | dtg.DefaultCellStyle.WrapMode = DataGridViewTriState.True; | 1 |
267 | r.DefaultCellStyle.BackColor = Color.Red; | 2 |
326 | r.DefaultCellStyle.BackColor = Color.Red; | 3 |
File name: usableFunction.cs
Copy
79 public void ResponsiveDtg(DataGridView dtg)
80 {
81 dtg.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
82 }
File name: frmMainMenu.cs
Copy
249 public void GetData()
250 {
251 try
252 {
253 con = new SqlConnection(cs.DBConn);
254 con.Open();
255 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID group by Product.productID,productname,Price,Features,Quantity having(Quantity>0) order by ProductName";
256 cmd = new SqlCommand(sql, con);
257 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
258 dataGridView1.Rows.Clear();
259 while (rdr.Read() == true)
260 {
261 dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5]);
262 }
263 foreach (DataGridViewRow r in this.dataGridView1.Rows)
264 {
265 if (Convert.ToInt32(r.Cells[4].Value) < 10)
266 {
267 r.DefaultCellStyle.BackColor = Color.Red;
268 }
269 }
270 con.Close();
271 }
272 catch (Exception ex)
273 {
274 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
275 }
276 }
File name: frmMainMenu.cs
Copy
309 private void textBox1_TextChanged(object sender, EventArgs e)
310 {
311 try{
312 con = new SqlConnection(cs.DBConn);
313 con.Open();
314 String sql = "SELECT Product.ProductID,ProductName,Features,Price,sum(Quantity),sum(Price*Quantity) from Temp_Stock,Product where Temp_Stock.ProductID=Product.ProductID and ProductName like '" + txtProductName.Text + "%' group by product.ProductID,productname,Price,Features,Quantity having(quantity>0) order by ProductName";
315 cmd = new SqlCommand(sql, con);
316 rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
317 dataGridView1.Rows.Clear();
318 while (rdr.Read() == true)
319 {
320 dataGridView1.Rows.Add(rdr[0], rdr[1], rdr[2], rdr[3], rdr[4], rdr[5]);
321 }
322 foreach (DataGridViewRow r in this.dataGridView1.Rows)
323 {
324 if (Convert.ToInt32(r.Cells[4].Value) < 10)
325 {
326 r.DefaultCellStyle.BackColor = Color.Red;
327 }
328 }
329 con.Close();
330 }
331 catch (Exception ex)
332 {
333 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
334 }
335 }
DefaultCellStyle 120 lượt xem
Gõ tìm kiếm nhanh...