-1

I am connected to a Database. I created an DataViewGrid which uses Databinding from that Database. I want to use Rows and Columns as Headers, right now somehow there are just Columns as Headers. I am using Visual Studio 15 and want to use the Designer. Does anyone ever did that? Or know an better Windows.Form for creating Table, which are connected to the Database and have Headers at the Row and Column side?

Thx in advance

Montezuma
  • 49
  • 2
  • 12
  • I have no idea what you want. Display some info (which? row numbers as currently displaying? ) in the RowHeader cells? You need to assign it for each row as there is no natural content! – TaW Oct 27 '16 at 10:57
  • Nope plan is taking the data out of the database and displaying it in a table, but Datagridview just used column headers and i couldn't add rows as headers in the designer. But i will use PivotGrid, whichs seems to be good – Montezuma Oct 27 '16 at 16:33

2 Answers2

3

Your requirements are not very clear but I guess you want to customize the row and column headers. The dataGridView is probably one of the best controls to view data in Windows Forms. I will show how to do the following typical requirements would be;

  1. To show column headers in Title Case or UPPER Case
  2. Customize the column headers specific names
  3. Show row numbers on row headers

Code below is in C#

//Show Columns in Title, Lower(textInfo.ToLowerCase) or Upper case textInfo.ToUpperCase
    System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo;
    foreach (DataGridViewColumn col in dataGridView.Columns)
    {
        col.HeaderText = textInfo.ToTitleCase(col.HeaderText);
    }

//Customize specific column headers, using name or column index 
    dataGridView.Columns["number"].HeaderText = "No.";
    dataGridView.Columns["quantity"].HeaderText = "Product Quantity";
    dataGridView.Columns[0].HeaderText = "Code";    

//Set Row headers with numbers   
    int rowNumber = 1;
    foreach (DataGridViewRow row in dataGridView.Rows)
    {
        if (row.IsNewRow) continue;
        row.HeaderCell.Value = "Row " + rowNumber;
        rowNumber = rowNumber + 1;
    }
    dataGridView.AutoResizeRowHeadersWidth(
    DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);

Reference

Vectoria
  • 1,627
  • 14
  • 13
0

Thirdparty Grids like DevExpress PivotGrid allow you do to sth. like this. The basic dataGridView is not able to present RowHeader as far as i know. You could create a custom column to your DataSource, which holds RowHeader information and show this as first column. If you modify the first columns layout a bit it looks like RowHeader maybe. Would be the only trick i know with basic dataGridView.

Sebi
  • 3,879
  • 2
  • 35
  • 62
  • Thx, I tried this out, and it seems like having a lot of features, inculded having row and column headers – Montezuma Oct 27 '16 at 16:32
  • _The basic dataGridView is not able to present RowHeader as far as i know._ Well, it can. See Vectoria's answer. Recommending such an expensive product for stuff that is easily done by the out-of the box DGV is rather strange imo. – TaW Oct 27 '16 at 17:09