如何将数据网格列设置为来自 Windows Mobile 应用程序中数据库的超链接?

发布于 2024-11-23 23:08:54 字数 248 浏览 0 评论 0原文

在 Windows Mobile 应用程序中,我有 DataGrid 控件,它在 page_load 上显示来自 Database 的数据。 我希望 DataGrid 列充当 HyperLink ,以便 MessageBox 或另一个窗口 Form 将打开并显示详细内容选定的 DatGrid 列。

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 .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷→糖丶微凉 2024-11-30 23:08:54

则只需捕获单击事件并使用该列的内容即可打开您的网址

如果您有一个包含三列的表,每列包含一个 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;

。然后,您可以将其用作超链接。

    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());
    }

如果您只希望某个列启动您的链接,那么只需通过检查列号来考虑这一点。

    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());
        }
    }

从你的问题来看,你想要实现的目标有点不清楚,但如果你只是想在消息框中显示该项目......

    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());
        }
    }

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());
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文