2011-10-08 11 views

उत्तर

19

DataGridView की CellFormatting घटना संभाल और सेल एक चयनित पंक्ति के अंतर्गत आता है, तो फ़ॉन्ट के लिए एक साहसिक शैली लागू:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) 
{ 
    var dataGridView = sender as DataGridView; 
    if (dataGridView.Rows[e.RowIndex].Selected) 
    { 
    e.CellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Bold); 
    // edit: to change the background color: 
    e.CellStyle.SelectionBackColor = Color.Coral; 
    } 
} 
+0

सहायता के लिए धन्यवाद अंतिम पंक्ति है! और पंक्ति के बैककोलर को कैसे बदला जाए? – Gali

+0

क्या सेल में केवल कुछ शब्दों को बोल्ड करना संभव है, पूरे सेल में नहीं? मुझे हाइलाइट दिखाने के लिए इस कार्यक्षमता की आवश्यकता है, लेकिन मुझे नहीं पता कि इसे कैसे कार्यान्वित किया जाए? क्या यह सभी के लिए संभव है? – FrenkyB

+1

@ फ्रेंकीबी: कोड प्रोजेक्ट पर आलेख [डेटाग्रिड व्यू में रिचटेक्स्टबॉक्स सेल] (http://www.codeproject.com/Articles/31823/RichTextBox-Cell-in-a-DataGridView) देखें, लेकिन प्रदर्शन समस्याएं प्रतीत होती हैं ... शायद हो सकता है कि आपका डेटा केवल पढ़ा जाए, यह स्वीकार्य हो सकता है। –

0

डेटा GridView की SelectionChanged ईवेंट को संभालने का प्रयास करें और cell शैली सेट करें।

1

डाटाग्रिड में सामग्री लोड करने के बाद, इन ईवेंट हैंडलर को रोनेटर और रोवलेव पर लागू करें।

private void dg_RowEnter(object sender, DataGridViewCellEventArgs e) 
{ 
    System.Windows.Forms.DataGridViewCellStyle boldStyle = new System.Windows.Forms.DataGridViewCellStyle(); 
    boldStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold); 
    dg.Rows[e.RowIndex].DefaultCellStyle = boldStyle; 
} 

private void dg_RowLeave(object sender, DataGridViewCellEventArgs e) 
{ 
    System.Windows.Forms.DataGridViewCellStyle norStyle = new System.Windows.Forms.DataGridViewCellStyle(); 
    norStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular); 
    dg.Rows[e.RowIndex].DefaultCellStyle = norStyle; 
} 

कोडों का परीक्षण नहीं किया जाता है। लेकिन यह ठीक काम करना चाहिए।

उम्मीद है कि यह मदद करता है।

0

नीचे कोड चयनित पंक्ति के लिए बोल्ड शैली के तहत फॉन्ट कर देगा। "कुल" मेरे कोड

protected void gvRow_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
    if (e.Row.Cells[rowIndex].Text == "Total") 
    { 
    e.Row.Font.Bold = true; 
    } 
} 
} 
संबंधित मुद्दे

 संबंधित मुद्दे