获取中心组合框中的项目 [英] Get items in a centered combobox

查看:58
本文介绍了获取中心组合框中的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在网上搜索了如何以组合框为中心制作数据。

我找到了一个代码像这样:



Hi all,

I have searched the net about how to make a data in a combobox centered.
I found a code like this :

class Centered_ComboBox : ComboBox
{
    public Centered_ComboBox()
    {
        DrawItem += CenteredComboBox_DrawItem;
        this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
        this.DropDownStyle = ComboBoxStyle.DropDownList;
    }

    public void CenteredComboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
        e.DrawBackground();
        string txt = "";
        if (e.Index >= 0)
            txt = this.Items[e.Index].ToString();
        TextRenderer.DrawText(e.Graphics, txt, e.Font, e.Bounds, e.ForeColor, TextFormatFlags.HorizontalCenter);
        e.DrawFocusRectangle();
    }
}





真的很完美,但是当我使用SQL中的数据绑定时我发现Combobox中的所有数据都写成:System.Data.DataRowView



我需要帮助编辑这段代码才能满足我的需求,

提前致谢。





祝你好运,

Michael Waguih

:)



And really it was perfect but when I use data Binding from SQL I found that all the data in the Combobox are written as: System.Data.DataRowView

Please I need help editing this code to achieve my needs,
Thanks in advance.


Best regards,
Michael Waguih
:)

推荐答案

您可以将用作输入的字符串的数据表转换为字符串数组,该字符串数组应该排除行为。



它与居中无关。

当这一行:

You can convert the datatable of string that you use as input to an array of strings, that should sort out the behavior.

It has nothing to do with the centering.
When this line:
txt = this.Items[e.Index].ToString();



获取一个DataRowView作为输入,然后ToString方法当然会声明它是一个DataRowView,它是它的结果ToString()实现。



您当然也可以覆盖ToString方法。

您还可以在 Centered_ComboBox <中插入支票/ code>用于检查输入类型并执行相应操作的类 - 在 CenteredComboBox_DrawItem 方法中处理不同类型。



干杯,

Edo


gets a DataRowView as input, then the ToString method will of course state that it is a DataRowView which is the result of it''s ToString() implementation.

You can of course also override the ToString method.
You can also insert a check in the Centered_ComboBox class to check the type of the input and act accordingly - handle different types in the CenteredComboBox_DrawItem method.

Cheers,
Edo


这篇关于获取中心组合框中的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆