开发者

How can I make datagrid column as HyperLink which is from database in windows mobile application?

开发者 https://www.devze.com 2023-03-20 01:41 出处:网络
In windows mobile application I have DataGrid control which displays data from Database on page_load.

In windows mobile application I have DataGrid control which displays data from Database on page_load. I want DataGrid column act as HyperLink so that MessageBox or another window Form will open and show the detail contents of selected 开发者_高级运维DatGrid column .


You can just capture the click event and use the contents of the column to open your web address

If you had a table with three columns each containing a url.

    DataTable dataTable = new DataTable();
    dataTable.Columns.Add("Website1", typeof(String));
    dataTable.Columns.Add("Website2", typeof(String));
    dataTable.Columns.Add("Website3", typeof(String));

    DataRow dr = dataTable.NewRow();
    dr["Website1"] = "http://www.bbc.co.uk";
    dr["Website2"] = "http://www.ebay.co.uk";
    dr["Website3"] = "http://www.google.co.uk";
    dataTable.Rows.Add(dr);

    dataGrid1.DataSource = dataTable;

You can then use that as a hyperlink

    private void dataGrid1_Click(object sender, EventArgs e)
    {
        int rowNumber = dataGrid1.CurrentCell.RowNumber;
        int columnNumber = dataGrid1.CurrentCell.ColumnNumber;

        System.Diagnostics.Process.Start("iexplore.exe", 
                       dgSites[rowNumber, columnNumber].ToString());
    }

If you only want a certain column to launch your link then just take that into account by checking the column number.

    private void dataGrid1_Click(object sender, EventArgs e)
    {
        int rowNumber = dataGrid1.CurrentCell.RowNumber;
        int columnNumber = dataGrid1.CurrentCell.ColumnNumber;

        if (columnNumber == 2)
        {
          System.Diagnostics.Process.Start("iexplore.exe", 
                       dgSites[rowNumber, columnNumber].ToString());
        }
    }

It is a little unclear from your question exactly want you are trying to achieve but if you just want to show the item in a message box...

    private void dataGrid1_Click(object sender, EventArgs e)
    {
        int rowNumber = dataGrid1.CurrentCell.RowNumber;
        int columnNumber = dataGrid1.CurrentCell.ColumnNumber;

        if (columnNumber == 2)
        {
          MessageBox.Show(dgSites[rowNumber, columnNumber].ToString());
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号