0

I am trying to add a tooltip to a specific column that may or may not be present, depending on the results of an sqlite query. The columnheaders are filled in from the query results.

I have this code to fill the datagrid:

SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataAdapter sda = new SQLiteDataAdapter(command);
sda.Fill(dt);
MainDataGrid.ItemsSource = dt.DefaultView;

I would like to do something like:

if(ColumnHeader == "Gauge")
{Column.Tooltip.Text = "Double click Gauge # to view details";} //Tooltip shows for entire column

But, I can't imagine it's that easy. I am completely self taught in c# and wpf, so a lot of my problems come from not knowing how to word the question properly. I am not looking for a copy-paste answer. Just a link(s) and an explanation.

dan
  • 23
  • 5
  • [Here is duplicate](https://stackoverflow.com/q/1164288/1997232) if `AutoGenerateColumns="False"`. In either case you can simply enumerate `MainDataGrid.Columns`. – Sinatr Nov 27 '17 at 10:15

1 Answers1

0

I used the following code:

void MainDataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
    {
        string tooltip = null;

        switch (e.Column.Header.ToString())
        {
            case "Gauge":
                tooltip = "Double click Gauge ID to view its details";
                break;
        }

        if (tooltip != null)
        {
            var style = new Style(typeof(DataGridCell));
            style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, tooltip));
            e.Column.CellStyle = style;
        }
    }

I got it here: Setting ToolTip for DataGridView automatically created columns

Thanks @Sinatr for getting me started in the right path.

dan
  • 23
  • 5