을 CheckedListBox :내가이 시나리오를
[Flags]
enum Colors : long
(
red = 1,
blue = 2,
green = 4,
yellow = 8,
)
DataTable dt = new DataTable();
dt.Columns.Add("PersonName", typeof(string));
dt.Columns.Add("CheckOption", typeof(bool));
dt.Columns.Add("Colors", typeof(long));
// note that the values in the Colors column are enumed values of chosen colors
dt.Rows.Add("Name 1", true, 1); // red
dt.Rows.Add("Name 2", true, 12); // green and yellow
dt.Rows.Add("Name 3", true, 4); // green
dt.Rows.Add("Name 4", false, 11); // red, blue and yellow
// bind the datatable to grid
DataGridView dgv = new DataGridView();
dgv.DataSource = dt;
// hide the colors in the grid
dgv.Columns["Colors"].Visible = false;
// checked list box has all items from the enum
CheckedListBox clb = new CheckedListBox();
string[] colorsArray = Enum.GetNames(typeof(Colors));
clb.Items.AddRange(colorsArray);
내가 원하는 것은 어떻게 든의 CheckedListBox에 데이터 테이블의 "색상"열에서 선택한 색상의 enumed 값을 결합하는 것입니다 좋은 방법. 가능합니까?
지금까지 그리드의 RowEnter 이벤트를 가지고 놀았지만 매우 부서지기 쉽고 전혀 좋지 않은 것처럼 보입니다.
편집 : 난으로 myText라는 데이터 테이블에서 4 번째 열이 있다면, 예를 들어 것은이 같은 텍스트 상자에 해당 열을 바인딩 할 수 있습니다 :
myTextBox.DataBindings.Add("Text", dt, "MyText");
데이터 그리드 가치의 행을 통해 이동 텍스트 상자가 자동으로 변경되고 텍스트 상자의 모든 업데이트가 다시 데이터 테이블에 저장됩니다. checklistbox 및 enum에서이 기능을 얻고 싶습니다.
나는 어떤 색상이 선택되었는지 알아 내는데 문제가 없습니다. 내가 원하는 것은 그 값을 체크리스트 상자에 바인딩하여 DataGrid의 행이 선택 될 때마다이 계산을 수행 할 필요가 없기 때문입니다. –
죄송합니다. 어떻게하는지 모르겠습니다. 그러나 그 값을 바인드 할지라도 행이 선택 될 때마다 다시 계산할 것입니다. 맞습니까? 더 추상적 인 것입니다. –
그래, 내가해야 할 것 같아. 나는 쉬운 길을 찾고 있었다 :) –