c# - 显示 MySql 数据的表,用户可以编辑该数据

标签 c# mysql winforms user-interface

我正在开发一个 C# 应用程序,需要为用户提供一个用户友好的工作环境。这个想法是用户使用他/她的 ID 和密码,因此只有与用户相关的数据才会显示在一张 table 。我已经弄清楚如何做到这一点,但现在用户需要能够编辑表格的内容,因为这一切都是为了给用户提供友好的界面。

我应该使用什么类似表格的组件来实现此目的?我需要能够加载数据并将编辑后的数据保存回数据库中,但我还需要能够为各个单元格和边框分配颜色,以使其看起来更加用户友好。另外,我更喜欢通过单击并编辑的方式来编辑表格内容。

我已经尝试使用 DataGridView,但它在自定义其外观方面表现不佳。

还有其他好的 .net 组件可以用来实现此目的吗?

<小时/>

编辑:它是一个 Windows 窗体桌面应用程序。

最佳答案

将单元格绑定(bind)到数据网格时,使用 CellFormatting 事件更改单个单元格

我自己的代码示例:

private void dgColorCodeKey_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{  
    if (e.RowIndex >= 0)
    {
        //if we are binding a cell in the Color column
        if (e.ColumnIndex == colColor.Index)
        {
            //ColorCode is a custom object that contains the name of a System.Drawing.Color
        ColorCode bindingObject = (ColorCode)dgColorCodeKey.Rows[e.RowIndex].DataBoundItem;
        dgColorCodeKey[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.FromName(bindingObject.Color);

        //set this property to true to tell the datagrid that we've applied our own formatting
        e.FormattingApplied = true;
        }
    }
}

此外,请参阅此 Data Grid FAQ对于数据网格如何工作以及各种方法和事件的作用有一个非常好的、清晰的描述。

关于c# - 显示 MySql 数据的表,用户可以编辑该数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1707779/

相关文章:

mysql - 无法添加外键约束,mysql工作台中出现错误1215。

php - 将 MySQL 结果转换为逗号分隔值

c# - gridview 中的 cellendedit 事件在另一个 gridview 中添加行?

c# - 如何在文本框中设置光标位置

c# - 使用接口(interface)引用变量调用基类方法

c# - 系统.绘图.图形

c# - Web服务调用Web方法

java - 将 Spring Boot 中的嵌入式数据库从 H2 更改为 MySQL

c# - Windows 窗体应用程序的 Web 界面

c# - 如何过滤 asp.net core 项目上的列表