نمایش نتایج 1 تا 2 از 2

نام تاپیک: تغییر رنگ دیتا گرید و سطر عنوان آن

  1. #1

    Question تغییر رنگ دیتا گرید و سطر عنوان آن

    با سلام می خواستم بدونم اگر بخواهم سطر اول دیتاگرید را یعنی همان سطری که عنوان ستون ها د رآن قرار می گیرد را رنگی کنم چه کدی را در کجا باید وارد کنم
    و همین طور اگر بخواهم سطر خاصی را رنگی کنم یعنی فقط یک سطر را چه کدی باید به کار ببرم و در گجا بنویسم

  2. #2
    کاربر دائمی آواتار pesar irooni
    تاریخ عضویت
    بهمن 1386
    محل زندگی
    تهران
    سن
    40
    پست
    495

    نقل قول: تغییر رنگ دیتا گرید و سطر عنوان آن

    برای رنگی کردن یه سطر خاص (i شماره سطر)

    dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;

    و برای تغییر رنگ header :
    dataGridView1.ColumnHeadersDefaultCellStyle.BackCo  lor = Color.Yellow;

    برای مشاهده تغییرات رنگ header حتما باید این کد رو قبلش بذاری

    dataGridView1.EnableHeadersVisualStyles =
    false;

    برای تغییر style تو msdn این کد نوشته شده که رنگ header رو هم تغییر میده.
    // Configures the appearance and behavior of a DataGridView control.
    private void InitializeDataGridView()
    {
    // Initialize basic DataGridView properties.
    dataGridView1.Dock = DockStyle.Fill;
    dataGridView1.BackgroundColor = Color.LightGray;
    dataGridView1.BorderStyle = BorderStyle.Fixed3D;
    // Set property values appropriate for read-only display and
    // limited interactivity.
    dataGridView1.AllowUserToAddRows = false;
    dataGridView1.AllowUserToDeleteRows = false;
    dataGridView1.AllowUserToOrderColumns = true;
    dataGridView1.ReadOnly = true;
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;
    dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
    dataGridView1.AllowUserToResizeColumns = false;
    dataGridView1.ColumnHeadersHeightSizeMode =
    DataGridViewColumnHeadersHeightSizeMode.DisableRes izing;
    dataGridView1.AllowUserToResizeRows = false;
    dataGridView1.RowHeadersWidthSizeMode =
    DataGridViewRowHeadersWidthSizeMode.DisableResizin g;
    // Set the selection background color for all the cells.
    dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White;
    dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;
    // Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
    // value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
    dataGridView1.RowHeadersDefaultCellStyle.Selection BackColor = Color.Empty;
    // Set the background color for all rows and for alternating rows.
    // The value for alternating rows overrides the value for all rows.
    dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray;
    dataGridView1.AlternatingRowsDefaultCellStyle.Back Color = Color.DarkGray;
    // Set the row and column header styles.
    dataGridView1.ColumnHeadersDefaultCellStyle.ForeCo lor = Color.White;
    dataGridView1.ColumnHeadersDefaultCellStyle.BackCo lor = Color.Black;
    dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black;
    // Set the Format property on the "Last Prepared" column to cause
    // the DateTime to be formatted as "Month, Year".
    dataGridView1.Columns["Last Prepared"].DefaultCellStyle.Format = "y";
    // Specify a larger font for the "Ratings" column.
    using (Font font = new Font(
    dataGridView1.DefaultCellStyle.Font.FontFamily, 25, FontStyle.Bold))
    {
    dataGridView1.Columns["Rating"].DefaultCellStyle.Font = font;
    }
    // Attach a handler to the CellFormatting event.
    dataGridView1.CellFormatting += new
    DataGridViewCellFormattingEventHandler(dataGridVie w1_CellFormatting);
    }

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •